B
B
Barberry2019-09-10 02:30:30
1C-Bitrix
Barberry, 2019-09-10 02:30:30

How to make check of delayed ShowProperty function?

How to make a check of the deferred function ShowProperty,
in the news component > in the detailed template of the component I set

$APPLICATION->SetPageProperty("H_tit", "какой-то текст"; ?>

In the h1 tag that is above the generate (the reason GetProperty doesn't work), I get <?php $APPLICATION->ShowProperty("H_tit"); ?> The
question is how to make a check condition, it won't work like this:
<h1><?php 
            $H_tit = $APPLICATION->GetProperty("H_tit");
            if (strlen($H_tit)>0 ): ?>
              <?php $APPLICATION->ShowProperty("H_tit"); ?>
              <?php else: ?>
              <?$APPLICATION->ShowTitle()?>
              <?php endif ?></h1>

and so it does not plow correctly:
<h1><?php 
            $H_tit = $APPLICATION->ShowProperty("H_tit");
            if (strlen($H_tit)>0 ): ?>
              <?php $APPLICATION->ShowProperty("H_tit"); ?>
              <?php else: ?>
              <?$APPLICATION->ShowTitle()?>
              <?php endif ?></h1>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Gritsuk, 2019-09-10
@winer

Here is what Bitrix says about deferred functions:

Attention! When using this technology, you must take into account that you cannot perform any actions on the results of the work of functions that provide the deferral of other functions.
The value returned by the deferred function is not returned, but immediately rendered at the call site of AddBufferContent, and whatever is rendered in the deferred function will be rendered before the start of the template.

Read the documentation carefully and you write:
If you call $APPLICATION->SetPageProperty in template.php your code won't work if caching is enabled. You can read more about this here
. If I understand correctly, you are trying to set h1 somewhere in the site template.
Use this cheat sheet:
$APPLICATION->SetTitle("Заголовок 1"); //- задать заголовок страницы
$APPLICATION->SetPageProperty('title','Заголовок 2');// - тоже задать заголовок страницы (но эта функция имеет приоритет над первой)
<?$APPLICATION->ShowTitle()?> - показ заголовка страницы  // покажет заголовок 1
<?$APPLICATION->ShowTitle(false)?> - показ заголовка страницы, заданного через SetTitle // покажет заголовок 2

A
Alexey Zakharov, 2019-09-10
@konratnox

Here is an example through deferred functions, you can do it by analogy. As already noted, SetPageProperty must be called in component_epilog.php
How to find out that we are in the product card of the catalog component?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question