Вывод сайдбара при условии наличия потомков или родителей.
Всем доброго временеи суток.
Прошу тапками сильно не кидаться, только начал изучение MODx Revo.
Сажаю шаблон на систему. В шаблоне есть просто страница без сайдбара и страница с левым сайдбаром. В сайдбаре находится только меню (PdoMenu) данного раздела. Хочу сделать в шаблоне простую логику: если у ресурса есть потомки или родители, то показываем чанк с html кодом и pdomenu в нем. Если нет, то не показываем. Подскажите пожалуйста, как это правильно реализовать?
p.s.
шаблон без меню:
Прошу тапками сильно не кидаться, только начал изучение MODx Revo.
Сажаю шаблон на систему. В шаблоне есть просто страница без сайдбара и страница с левым сайдбаром. В сайдбаре находится только меню (PdoMenu) данного раздела. Хочу сделать в шаблоне простую логику: если у ресурса есть потомки или родители, то показываем чанк с html кодом и pdomenu в нем. Если нет, то не показываем. Подскажите пожалуйста, как это правильно реализовать?
p.s.
шаблон без меню:
<!-- begin content -->
<section id="content" class="container clearfix">
<!-- begin page header -->
<header id="page-header">
<h1 id="page-title">[[*pagetitle]]</h1>
</header>
<!-- end page header -->
<!-- begin main content -->
[[*content]]
<!-- end main content -->
</section>
<!-- end content -->
шаблон с меню:<!-- begin content -->
<section id="content" class="container clearfix">
<!-- begin page header -->
<header id="page-header">
<h1 id="page-title">[[*pagetitle]]</h1>
</header>
<!-- end page header -->
<!-- begin sidebar -->
<aside id="sidebar" class="one-fourth">
[[$widget.navigation]]
</aside>
<!-- end sidebar -->
<!-- begin main content -->
<section id="main" class="three-fourths column-last">
[[*content]]
</section>
<!-- end main content -->
</section>
<!-- end content -->
Комментарии: 6
Попробуйте сделать сниппет Sidebar:
В шаблоне:
Чанк sidebar:
<?php
$child = $modx->getCount('modResource', array('parent'=>$resource->get('id')));
$parent = $resource->get('parent');
if($parent != 0 || $child > 0) return $modx->getChunk($tpl);
В шаблоне:
<!-- begin content -->
<section id="content" class="container clearfix">
<!-- begin page header -->
<header id="page-header">
<h1 id="page-title">[[*pagetitle]]</h1>
</header>
<!-- end page header -->
[[Sidebar? &tpl=`sidebar`]]
<!-- begin main content -->
<section id="main" class="three-fourths column-last">
[[*content]]
</section>
<!-- end main content -->
</section>
<!-- end content -->
Чанк sidebar:
<!-- begin sidebar -->
<aside id="sidebar" class="one-fourth">
[[$widget.navigation]]
</aside>
<!-- end sidebar -->
Спасибо!
Но при наличии сайдбара, страница бьется на колонки и добавляется html код с закрывающим тегом.
Но при наличии сайдбара, страница бьется на колонки и добавляется html код с закрывающим тегом.
<section id="main" class="three-fourths column-last">
Можно так:
Шаблон:
<?php
$child = $modx->getCount('modResource', array('parent'=>$resource->get('id')));
$parent = $resource->get('parent');
if($parent != 0 || $child > 0)
$modx->setPlaceholder('section_start', '<section id="main" class="three-fourths column-last">');
$modx->setPlaceholder('section_end', '</section>');
return $modx->getChunk($tpl);
}
Шаблон:
<!-- begin content -->
<section id="content" class="container clearfix">
<!-- begin page header -->
<header id="page-header">
<h1 id="page-title">[[*pagetitle]]</h1>
</header>
<!-- end page header -->
[[Sidebar? &tpl=`sidebar`]]
<!-- begin main content -->
[[+section_start]]
[[*content]]
[[+section_end]]
</section>
<!-- end main content -->
</section>
<!-- end content -->
Еще раз спасибо!
Написал как вы сказали, что получаю ошибку 500
Could not find snippet with name.
Шаблон:
Написал как вы сказали, что получаю ошибку 500
Could not find snippet with name.
Шаблон:
[[sidebar? &tpl=`tpl.sidebar`]]
<!-- begin main content -->
[[+section_start]]
[[*content]]
[[+section_end]]
tpl.sidebar:<!-- begin sidebar -->
<aside id="sidebar" class="one-fourth">
[[$widget.navigation]]
</aside>
<!-- end sidebar -->
Сниппет sidebar:<?php
$child = $modx->getCount('modResource', array('parent'=>$resource->get('id')));
$parent = $resource->get('parent');
if($parent != 0 || $child > 0) {
$modx->setPlaceholder('section_start', '<section id="main" class="three-fourths column-last">');
$modx->setPlaceholder('section_end', '</section>');
return $modx->getChunk($tpl);
}
Ошибка в переменных $child и $parent, т.к. если им присвоить 0, то все отрабатывает. Странно как-то.
Да, прошу прощения, ошибся ):
<?php
$child = $modx->getCount('modResource', array('parent'=>$modx->resource->get('id')));
$parent = $modx->resource->get('parent');
if($parent != 0 || $child > 0) {
$modx->setPlaceholder('section_start', '<section id="main" class="three-fourths column-last">');
$modx->setPlaceholder('section_end', '</section>');
return $modx->getChunk($tpl);
}
Все отлично! Еще раз большое спасибо!
Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.