• Mayd
  • OSS
  • Becklyn
  • mojave
  • kaba
  • samos
  • Overview
  • Frontend
  • Backend
  • Pages
  • Forms
  • Migration
  • Internals
  • Home
  • Mayd
  • Pages
  • Navigation
Pages
  • Finding Pages
  • Navigation
  • Page Properties
  • Page Tree

Navigation

Rendering Menus

You can render any menu for any website with the twig function:

{{- render_menu(website, "example-menu", {depth: 3}) -}}
parameters
nametypedescription
websiteWebsiteThe website where the navigation is in.
locationstring|nullThe location of the navigation
optionsarrayOptions 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
  • Rendering Menus
  • Modifying Navigation Items

Made with ❤ by Becklyn Studios