Korusol
12/13/2018 - 10:47 AM

Сео шаблоны битрикса через апи

$Section = [];
$seoProperties = [];
$entity = \Bitrix\Iblock\Model\Section::compileEntityByIblock($arParams["IBLOCK_ID"]);
$Section = $entity::getList(array(
    'select' =>  array('ID', 'UF_SEO_KEYWORDS', 'UF_SEO_TITLE', 'UF_DESCRIPTION', 'UF_SEO_PAGE_TITLE'),
    'filter' => array(
        'IBLOCK_ID' => $arParams["IBLOCK_ID"],
        'CODE' => $arResult["VARIABLES"]["SECTION_CODE"]
    ),
))->fetch();


if(!empty($Section)) {
    if($Section['ID'] > 0) {
        $ipropSectionValues = new \Bitrix\Iblock\InheritedProperty\SectionValues($arParams["IBLOCK_ID"],$Section['ID']);

        $seoProperties = $ipropSectionValues->getValues();

    }
}

if (!empty($seoProperties)) {

    $title = $Section['UF_SEO_TITLE'] != '' ? $Section['UF_SEO_TITLE'] : $seoProperties['SECTION_META_TITLE'];
    $keywords = $Section['UF_SEO_TITLE'] != '' ? $Section['UF_SEO_KEYWORDS'] : $seoProperties['SECTION_META_KEYWORDS'];
    $description = $Section['UF_DESCRIPTION'] != '' ? $Section['UF_DESCRIPTION'] : $seoProperties['SECTION_META_DESCRIPTION'];
    $pageTitle = $Section['UF_SEO_PAGE_TITLE'] != '' ? $Section['UF_SEO_PAGE_TITLE'] : $seoProperties['SECTION_PAGE_TITLE'];

    $APPLICATION->SetPageProperty('title', $title);
    $APPLICATION->SetPageProperty('keywords', $keywords);
    $APPLICATION->SetPageProperty('description', $description);
    $APPLICATION->SetTitle($pageTitle);
}