Navigation
Rendering Menus
You can render any menu for any website with the twig function:
{{- render_menu(website, "example-menu", {depth: 3}) -}}
parameters
name | type | description |
---|---|---|
website | Website | The website where the navigation is in. |
location | string|null | The location of the navigation |
options | array | Options for rendering the navigation. These are the KnpMenu render options. |
If you want to render the main navigation, pass null
as location to the function. If you pass a string, the menu at the given location is rendered.
The options are the KnpMenu render options.
Modifying Navigation Items
While the navigation trees are automatically built from your page tree or menu tree, you have the ability to modify navigation items using menu item visitors.
use Knp\Menu\ItemInterface;
use Mayd\Pages\Menu\Builder\ItemVisitor\MenuItemVisitorInterface;
use Mayd\Pages\Menu\Item\MenuItemInterface;
class SomeVisitor implements MenuItemVisitorInterface
{
public function visitNode (ItemInterface $item, MenuItemInterface $node) : void
{
// only modify the item for the page 123
if (!$node instanceof Page || 123 !== $node->getId())
{
return;
}
// remove the item ...
$item->getParent()->removeChild($item->getName());
// ... or changing an attribute ...
$item->setUri("https://becklyn.tech");
$item->Attribute("data-target", "https://becklyn.tech");
// ... or adding extra info ...
$item->setExtra("icon", "doner");
// ... or adding additional elements
foreach ($subPages as $label => $uri)
{
$item->addChild($label, [
"label" => $label,
"uri" => $uri,
]);
}
}
}
You need to tag your service with the tag mayd.pages.menu_item_visitor
.
If you use autoconfiguration, that tag will automatically be added.
Table of Contents