Question

I found a way to add a static block in a dropdown. I edited the renderer.phtml in page/html/topmenu and added:

$html .= '<ul class="level' . $childLevel . '">';
$html .= $this->_getHtml($child, $childrenWrapClass);
$staticBlock = trim($this->getLayout()->createBlock('cms/block')-
>setBlockId($child->getId())->toHtml());
if(!empty($staticBlock)){
$html .= '<span>';
$html .= $staticBlock;
$html .= '</span>';
}
$html .= '</ul>';

Now I want t show a different static block in every menu items dropdown. So based on the top category, a different static block should be called.

What would be the best way to do that?

The code I used is this:

staticBlock = trim($this->getLayout()->createBlock('cms/block')->setBlockId('top-5')->toHtml());
    $html .= '<span class="nav-static-block">';
    $html .= $staticBlock;
    $html .= '</span>';
    $html .= '</ul>';
Was it helpful?

Solution

You can directly use your first code,

$html .= '<ul class="level' . $childLevel . '">';
$html .= $this->_getHtml($child, $childrenWrapClass);
$staticBlock = trim($this->getLayout()->createBlock('cms/block')-
>setBlockId($child->getId())->toHtml());
if(!empty($staticBlock)){
    $html .= '<span>';
    $html .= $staticBlock;
    $html .= '</span>';
}
$html .= '</ul>';

All you need to do is to update your static block ids like category-node-8 here category-node- will be static and 8 will be the id of the category.

If you have a static block with ID top-5 change its id to category-node-5 and it will get displayed under your category with ID 5.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top