Вывод сайдбара при условии наличия потомков или родителей.

Всем доброго временеи суток.
Прошу тапками сильно не кидаться, только начал изучение 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 -->
Andrey
24 ноября 2017, 08:48
modx.pro
1
2 352
0

Комментарии: 6

Павел Романов
24 ноября 2017, 11:59
0
Попробуйте сделать сниппет 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 -->
    Andrey
    24 ноября 2017, 12:07
    0
    Спасибо!
    Но при наличии сайдбара, страница бьется на колонки и добавляется html код с закрывающим тегом.
    <section id="main" class="three-fourths column-last">
      Павел Романов
      24 ноября 2017, 12:19
      0
      Можно так:
      <?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 -->
        Andrey
        24 ноября 2017, 14:43
        0
        Еще раз спасибо!
        Написал как вы сказали, что получаю ошибку 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, то все отрабатывает. Странно как-то.
          Павел Романов
          24 ноября 2017, 14:51
          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);
          }
            Andrey
            24 ноября 2017, 15:03
            0
            Все отлично! Еще раз большое спасибо!
    Авторизуйтесь или зарегистрируйтесь, чтобы оставлять комментарии.
    6