Exclude pages in treemenu

Thank you both for your help. This works fine for the breadcrumb.

My next issue in this case is the tree menu. I want to show only the content of the support folder and it’s subfolders there.

<?php if(!isset($subpages)) $subpages = $site->children() ?>
<ul>
  <?php foreach($subpages->visible() AS $p): ?>
  <li class="depth-<?php echo $p->depth() ?>">
  
    <!-- My try starts here -->
    <?php if (!$page->find('support')): ?>
      
      <?php echo $subpages->visible() ?>
    <?php endif ?>
    <!-- My try ends here -->


    <a<?php e($p->isActive(), ' class="active"') ?> href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a>
    <?php if($p->hasChildren()): ?>
    <?php snippet('treemenu_knowledge', array('subpages' => $p->children())) ?>
    <?php endif ?>
  </li>
  <?php endforeach ?>
</ul>

As you can see, I try to filter by the keyword ‘support’ to get rid of the not needed folders. But still fails.

    <?php if (!$page->find('**support**')): ?>
      <?php echo $subpages->visible() ?>
    <?php endif ?>

The idea is the same. Use everything in the support folder, nothing else.

My first try was to use the ‘$p’. Doesn’t work. I tried a lot, saw the recursive usage, but not able to hook in.

What I’m doing wrong here?

I know, that the nesting of the’ if/endif’ will be corrected later on.

To get this right:

Is the support folder a first level page?
If yes, do you want to show any other first level pages in the treemenu? Or do you only want to show the support folder and it’s subfolders and no other pages at all?

Yes, it is.

The content folder looks like:

01-RyCON
02-ZFEx
03-hive
04-support
05-blog
error
.... other folders like error
site.de.txt
site.en.txt

No.

Thats what I want. Only the support folder and every subfolder and pages inside.

Hello @texnixe

My last try was this:

<?php foreach($subpages->visible() AS $p): ?>
  <?php if(str::startsWith($p, 'support')): ?>
  [...]
  <?php endif ?>
<?php endforeach ?>

It works. But the question is, is this a good solution?

Easiest way:

<?php foreach($subpages->visible()->filterBy('uid', 'support')  AS $p): ?>
<!-- code -->
<?php endforeach ?>

Doesn’t work either.

Oh, sorry, it has to go into the first line:

<?php if(!isset($subpages)) $subpages = $site->children()->filterBy('uid', 'support') ?>
1 Like

Works like a charm. :blush: