A
A
Alena2014-03-03 17:37:46
PHP
Alena, 2014-03-03 17:37:46

How to set an SEO template for an element in Bitrix?

So, I have a new Bitrix functionality for SEOs that sets names, descriptions, keywords, etc. directly from the element/section/infoblock at the request of the SEO, there is the only example of setting a new template on the Internet:
Adding, changing and deleting meta templates tags

use Bitrix\Iblock\InheritedProperty; 

//ООП  ElementTemplates или SectionTemplates или IblockTemplates )) 
$ipropTemplates = new InheritedProperty\ElementTemplates($IBLOCK_ID, $SECTION_ID, $ELEMENT_ID);

 //Установить шаблон для элемента 
$ipropTemplates->set(array(
         "MY_PROP_CODE" => "{=this.mycode}",
         "SOME_CODE" => "", //Удалить шаблон
));

and there is a desire to set a new template that gives, for example, the sum of the PRICE1 and PRICE2 fields in the {=this.sumprice} template
Who has advice, wise thoughts, ideas for implementation?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alena, 2014-03-13
@Alien-Ka

It turned out that a new text template is installed like this:

$ipropTemplates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($arResult["IBLOCK_ID"], $arResult["ID"]);
$ipropTemplates->set(array(
"MY_PROP_CODE" => 'Покупайте {=concat this.name section.name "_"} осталось всего '.$count.' штук', 
));

they are available via request
$iTemplates = new \Bitrix\Iblock\InheritedProperty\ElementTemplates($arResult["IBLOCK_ID"], $arResult["ID"]);
$templates = $iTemplates->findTemplates();

The resulting array is $templates
[MY_PROP_CODE] => Array
        (
            [ID] => 29
            [CODE] => MY_PROP_CODE
            [TEMPLATE] => "Покупайте {=concat this.name section.name "_"} осталось всего 5 штук"
            [ENTITY_TYPE] => E
            [ENTITY_ID] => 21
            [INHERITED] => N
        )

    [ELEMENT_META_TITLE] => Array
        (
            [ID] => 30
            [CODE] => ELEMENT_META_TITLE
            [TEMPLATE] => Каталог {=this.Name} от магазина Одежда+ {=this.mycode}
            [ENTITY_TYPE] => E
            [ENTITY_ID] => 21
            [INHERITED] => N
        )

M
Maxim, 2014-03-04
@Tomio

Even before the appearance of this functionality, this problem on one of our projects was solved as follows:
1 - The "SEO-templates" infoblock was created, in which these template elements actually lay. When adding a new SEO template, the element had 3 properties: SEO-title, SEO-Description, SEO-keywords. Templates like: "Buy #NAME# at the price of #PRICE# at competitive prices in Moscow" were driven there (for SEO-title, for example).
2. In the infoblock with products, the sections have a new custom property "SEO-template" of the "Binding to infoblock elements" type.
3. In the element detail view template, these properties were pulled out by the section ID, and if they were not empty, then a simple str_replace("#NAME#", "$arResult["NAME"]", $seo_title) - etc. - a new title or meta tags were formed.
4. And thanks to the deferred function $APPLICATION->SetPageProperty("title", $seo_title); all this miracle was registered on the page.
Thus, we prescribed meta tags and titles for products in the section.

M
Maxim, 2014-03-04
@Tomio

But the question is interesting, it would also be useful to know how the list of SEO templates can be expanded in the current version of the BUS. Since it would be easier than the above.

R
ragermes, 2017-11-17
@ragermes

More interesting how to install SKU meta...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question