0

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>';
3
  • Can you add more details about the top category you are talking about? From your code it seems like you can create different static blocks with different ids and it will be displayed in menu section. Commented Sep 11, 2017 at 11:24
  • Here I can see you have different static block contents for each menu item. Now can you explain what is the issue here? Commented Sep 11, 2017 at 12:20
  • I updated the code above. It only calls one static block for all menu items. I need to show different blocks for different menu-items. So the satic block must be a variable based on category-ID
    – Marcel
    Commented Sep 11, 2017 at 12:24

1 Answer 1

1

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.

1
  • 1
    That is it. Thanks! That is what I wondered about the first code: how to make it relate to the category
    – Marcel
    Commented Sep 11, 2017 at 12:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.