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>';
- 
 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.Jaimin Sutariya– Jaimin Sutariya2017年09月11日 11:24:24 +00:00Commented 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?Jaimin Sutariya– Jaimin Sutariya2017年09月11日 12:20:28 +00:00Commented 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-IDMarcel– Marcel2017年09月11日 12:24:23 +00:00Commented Sep 11, 2017 at 12:24
1 Answer 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.
- 
 1That is it. Thanks! That is what I wondered about the first code: how to make it relate to the categoryMarcel– Marcel2017年09月11日 12:47:49 +00:00Commented Sep 11, 2017 at 12:47