Menu: 3rd level or just sub sub menu

Everybody who follows this

had got a running menu!

@dedani:
Why did you change the filename?

Let me add my additional explanation from the PM in case it is useful for others:

You include a snippet in your code by calling the snippet helper with the name of the snippet file without the .php ending.

If your snippet file is called treemenu.php, you call it like this:

<?php snippet('treemenu') ?>

If your snippet file is called submenu.php, you call it like this:

<?php snippet('submenu') ?>

Within the treemenu snippet, the snippet calls itself (after the comment):

<?php if(!isset($subpages)) $subpages = $site->children() ?>
<ul>
  <?php foreach($subpages->visible() AS $p): ?>
  <li class="depth-<?php echo $p->depth() ?>">
    <a<?php e($p->isActive(), ' class="active"') ?> href="<?php echo $p->url() ?>"><?php echo $p->title()->html() ?></a>
    <?php if($p->hasChildren()): ?>
    <!-- here the snippet is called from within the snippet -->
    <?php snippet('treemenu', array('subpages' => $p->children())) ?>
    <?php endif ?>
  </li>
  <?php endforeach ?>
</ul>

Therefore, the name of the snippet is important here. If the snippet you call does not exist, it is not included and the whole thing does not work as expected.

This is a recursive snippet (the same can be done with functions, we then call them recursive functions).

Hope this clarifies it.

1 Like

I don’t think we have to question people why they made a mistake. It happens to the best of us.

@anon77445132: Its easy to explain. There is no explaination how to name the file. I did not know that this is important. Just use the same name in the snippet.

-> submenu.php
-> <?php snippet('submenu') ?>

But thats not. You have to use the right name because its part of the script. If you wanna change the name, you have to change the script to. That wasnt clear.

After all: texnixe helped me and is right. To ask someone why he/ she did a mistake is the wrong way and (sorry) typically german, espacially in a forum. It has nothing to do with the topic :wink:

Hi @texnixe,

I’m trying to apply the snippet to the starter kit but it doesn’t apply it to the subpages. It shows basically all options on the first menu and not the submenus.

Could you help me out?
Screenshot 2022-10-12 at 11.50.51