Суть задачи
Нужно организовать вывод баннера на страницах ресурсов. Ресурсы заведены в контейнерах, для которых мы тоже можем выбрать баннер. Но выбор для отдельного ресурса - в приоритете. Сами баннера заведены в отдельном контейнере ресурсами (например это могут быть клиенты, баннера которых (они заведены тоже в TV) мы периодически показываем).
[[ReclamWidget? &tpl=`tpl.Reclama` &id=`[[*id]]` &parent=`[[*parent]]`]]
$output = '';
$parent = $modx->getOption('parent',$scriptProperties,'1');
$id = $modx->getOption('id',$scriptProperties,'1');
$page = $modx->getObject('modResource', $id);
$parent_page = $modx->getObject('modResource', $parent);
$banner_id = $page->getTVValue('sidebar_banner');
$banner_id_parent = $parent_page->getTVValue('sidebar_banner');
$published = $modx->getObject('modResource', $banner_id)->get('published');
$published_parent = $modx->getObject('modResource', $banner_id_parent)->get('published');
$banner_show = $page->getTVValue('show_sidebar_banner');
if($banner_id == '' || !$published || !$banner_show){
$banner_id = $banner_id_parent;
}
if($banner_id !== '' && $published_parent){
$banner = $modx->getObject('modResource', $banner_id);
$description = $banner->get('description');
$image = $banner->getTVValue('sidebar_banner_img');
$output = $modx->getChunk($tpl);
$modx->setPlaceholder("banner_image", $image);
$modx->setPlaceholder("banner_url", $description);
}else{
$output = '';
}
return $output;