Magento – MagentoEE CMS Hierarchy Menu in Header

cmsmagento-enterprisetheme

Using Magento EE, I have created a CMS Hierarchy (Admin > CMS > Pages > Manage Hierarchy). Each of the hierarchy items are set to Show in Navigation Menu > Yes under Page Navigation Menu Options. I would like to use this page hierarchy as a separate navigation menu in my header (as a super header navigation of sorts). The hierarchy must be its own separate menu, not part of the categories top menu.

In my local.xml layout, I have added a hierarchy menu block to my header, where I will be calling the hierarchy_menu template from:

<layout>
    <default>
        ...
        <reference name="header">
            <block type="enterprise_cms/hierarchy_menu" name="hierarchy_menu" template="cms/hierarchy/menu.phtml" />
        </reference>
        ...
    </default>
</layout>

In my page/html/header.phtml template, I am echoing the block:

<?php echo $this->getChildHtml('hierarchy_menu') ?>

My issue is that the hierarchy menu block is rendering on CMS pages ONLY. On non-CMS pages, this block either halts the rendering of the rest of the page or simply does not render the menu. I can't seem to figure out why this is occurring. I would like to be able to render the cms/hierarchy/menu.phtml block in the site header on every page.

Does anyone know what is happening here?

Best Answer

The menu is rendered using either the defined cms hierarchy node or falls back to the one found in the registry.

You can check the Enterprise_Cms_Block_Hierarchy_Menu file. The logic for selecting a node can be found in the _construct method.

    if ($this->getNodeId()) {
        $this->_node = Mage::getModel('enterprise_cms/hierarchy_node')
            ->load($this->getNodeId());
    } else {
        $this->_node = Mage::registry('current_cms_hierarchy_node');
    }

Upon rendering the cms/hierarchy/menu.phtml file. The getTree() method is executed. This method uses the $this->_node value, which is not defined on a non-cms page. Hence the page halts during rendering.

If you want to display this menu on all the pages you need to extend the _construct method of this block to always fall back to the top nodeId in the hierarchy. Or to a pre-defined ID (via a configuration item for example) when the node you want to use is not the top node in the full hierarchy of cms pages.