pbMenu
Resource tree for navigation.
[[!pbMenu? &parent=`0` &level=`3` &tpl=`chunk:menuItem`]]Parameters
| Parameter | Default | Description |
|---|---|---|
parent | 0 | Root of the tree. 0 means the site root. |
level | 3 | How many levels deep to walk. |
Plus the shared output parameters from Intro.
Each row carries its children
Unlike a flat list, every item has a children collection, so one chunk renders the whole tree by calling itself:
php
<li>
<a href="{$item->uri}">{$item->pagetitle}</a>
{if $item->children}
<ul>
{foreach $item->children as $item}
{include 'chunk:menuItem'}
{/foreach}
</ul>
{/if}
</li>{insert} and {include} share scope
The loop variable is visible inside the included chunk — that is what makes the recursion above work. It also means a variable you set in the parent can leak in and surprise you. Name loop variables deliberately.
Examples
Top-level menu, one level
[[!pbMenu? &level=`1` &tpl=`chunk:menuItem`]]Submenu of a section
[[!pbMenu? &parent=`[[*id]]` &level=`2` &tpl=`chunk:menuItem`]]From Fenom
php
{foreach menu(0, 2) as $item}
<a href="{$item->uri}">{$item->pagetitle}</a>
{/foreach}