You can achieve this with a partial view.
In the configuration file, for example. config / autoload / global.php:
return array(
'navigation' => array(
'default' => array(
array(
'label' => 'Home',
'route' => 'home',
),
array(
'label' => 'User',
'route' => 'user',
'pages' => array(
array(
'label' => 'List',
'route' => 'list',
),
array(
'label' => 'Add',
'route' => 'add',
),
array(
'label' => 'Edit',
'route' => 'edit',
),
),
),
array(
'label' => 'Options',
'route' => 'options',
),
)
)
);
In your layout file, for example. view / layout / layout.phtml:
<nav>
<?php
echo $this->navigation('navigation')
->menu()
->setPartial('partial/menu')
->render();
?>
</nav>
Partial view, here view / partial / menu.phtml:
<ul>
<?php
foreach ($this->container as $page)
{
$hasChildren = $page->hasPages();
if( ! $hasChildren)
{
?>
<li><a href="<?php echo $page->getHref(); ?>"><?php echo $page->getLabel(); ?></a></li>
<?php
}
else
{
?>
<li>
<a href="<?php echo $page->getHref(); ?>"><?php echo $page->getLabel(); ?></a>
<ul>
<?php
foreach($page->getPages() as $child)
{
?>
<li><a href="<?php echo $child->getHref(); ?>"><?php echo $child->getLabel(); ?></a></li>
<?php
}
?>
</ul>
</li>
<?php
}
}
?>
</ul>
CSS, :
fooobar.com/questions/1520622/...