Add the menu to the frontend

With native Magento theme based on Luma :

In order to add a menu to the frontend view you can add this code to your layout xml file or in the layout update xml fields:

<block class="Blackbird\MenuManager\Block\Menu">
    <arguments>
        <argument name="menu" xsi:type="string">menu_identifier</argument>
    </arguments>
</block>

You can also add another parameter if you don't want to load the associated menu's Javascript (loaded by default or if the argument is set to true) :

<argument name="jquery_loading" xsi:type="boolean">false</argument>

With Hÿva Theme :

Install the compatibility module :

composer require hyva-themes/magento2-blackbird-menumanager

Use the MenuManagerViewModel to get your menu in templates (example with YourTheme/Magento_Theme/templates/html/header/menu/desktop.phtml):

Replace the native hyva logic :

/** @var Navigation $viewModelNavigation */
$viewModelNavigation = $viewModels->require(Navigation::class, $block);


$menuItems = $viewModelNavigation->getNavigation(4);
$block->setData('cache_tags', $viewModelNavigation->getIdentities());

With this logic :

$menuIdentifier = "MY_MENU_IDENTIFIER";

/** @var \Hyva\BlackbirdMenuManager\ViewModel\MenuTree $menuManagerViewModel */
$menuManagerViewModel = $viewModels->require(\Hyva\BlackbirdMenuManager\ViewModel\MenuTree::class);

// Order is important here: 1. build the menu data, 2. then set the cache tags from the view model identities
$menuItems = $menuManagerViewModel->getMenuItems($menuIdentifier, 5);
$block->setData('cache_tags', $menuManagerViewModel->getIdentities());

The native hyva view model \Hyva\Theme\ViewModel\Navigation can be replaced by the  \Hyva\BlackbirdMenuManager\ViewModel\MenuTree view model in any templates. Don't forget to update mobile.phtml for mobile menu.

loader
Loading...