R
R
ragnar_ok2020-12-11 22:18:43
1C-Bitrix
ragnar_ok, 2020-12-11 22:18:43

How to check if a page property exists (deferred functions)?

Russian-language and similar English-language information block "News" is given. Elements of these infoblocks are linked by the "Binding to infoblock element" property. It is necessary to display a bitrix:main.site.selectorlink to the related element in the component template (the component is called in header.php).

I set the page property in component_epilog.php with the value of the DETAIL_PAGE_URLassociated element:

if (!empty($arResult['PROPERTY_NEWS_ID_DETAIL_PAGE_URL'])) { // свойство "Привязка к элементу инфоблока"
    $APPLICATION->SetPageProperty('link', $arResult['PROPERTY_NEWS_ID_DETAIL_PAGE_URL']);
}


I display in template.php bitrix:main.site.selectorproperty: $APPLICATION->ShowProperty('link');

Answer the questions:
  1. Is it possible to check internally bitrix:main.site.selectorif the link page property exists? If it exists, then display its content, otherwise display a link to the main page of a foreign-language site (for example, en/ for the English language version).
  2. Is it allowed to use $APPLICATION->ShowProperty()a cacheable component in template.php?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
PetrPo, 2020-12-12
@ragnar_ok

move the component to the footer))

<?
ob_start();
  // вызов компонента
    $mainSiteSelectorComponent = ob_get_contents();
ob_end_clean();
$APPLICATION->AddViewContent('mainSiteSelectorComponent', $mainSiteSelectorComponent);
?>

In the header where the component was displayed
<?$APPLICATION->ShowViewContent('mainSiteSelectorComponent');?>

Further option 2:
1. In principle, as you correctly said, the template of this component is not cached, so you can freely get the value of the property in it
2. Pass the value to the component parameter, if the template was cacheable
Get the UPD property , respectively, and insert a check
$APPLICATION->GetProperty('link');
$propertyLink = $APPLICATION->GetProperty('link');
if($propertyLink) {

}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question