D
D
DeeUs2018-08-06 10:28:39
1C-Bitrix
DeeUs, 2018-08-06 10:28:39

Generation of meta tags, how to implement?

Hello!
To specify metadata and h1 (for sections), I created additional fields.
Added properties for product cards.
It is necessary to implement auto-generation of metadata for those sections/products for which they are not registered in new fields.
figured out how to get field values ​​for sections:

the code
if(0 < intval($arResult["VARIABLES"]["SECTION_ID"])) {
                        $arFilter["ID"] = $arResult["VARIABLES"]["SECTION_ID"];
                    } elseif("" != $arResult["VARIABLES"]["SECTION_CODE"]) {
                        $arFilter["=CODE"] = $arResult["VARIABLES"]["SECTION_CODE"];
                    }

                    $arSelect = array("UF_META_T", "UF_META_K", "UF_META_D", "UF_H1");

                    $rsSections = CIBlockSection::GetList(array(), $arFilter, false, $arSelect);
                    if($arSection = $rsSections->Fetch()) {

                        $_h1_ = $arSection["UF_H1"];
                        $_title_ = $arSection["UF_META_T"];
                        $_desc_ = $arSection["UF_META_D"];
                        $_keyw_ = $arSection["UF_META_K"];
                    }


(public_html\bitrix\templates\tshop\components\bitrix\catalog\main\section.php - here it seems to work as it should.)
But I don’t understand where to write setPageProperty().
tried writing in the same file as the code above - doesn't help
tried writing in component epilog - doesn't work either

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kudis, 2018-08-06
@kudis

In component_epilog, setPageProperty() works if your data reaches this file.
Do not forget about the cache and the need to remove data from it:

$this->setResultCacheKeys([
        'YOUR_PARAM',
    ]);

in general, all properties of the section, if you have rendered your data in this way, are available in the catalog component. You just need to fill in the data in the meta fields using the methods of deferred functions.
example from the docs :
$APPLICATION->AddBufferContent('ShowCondTitle');
function ShowCondTitle()
{
  global $APPLICATION;
 if (!$APPLICATION->GetTitle())
    return "Стандартная страница";
 else
    return $APPLICATION->GetTitle();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question