0

I have created a region in my theme that contains only menus. Each menu has its own visibility settings. For e.g. my main-menu is everywhere visible except at /blog/* and my blog-menu only at /blog/*. I use this as my main navigation bar region.

My issue is that i call this region in my page.tpl.php with

<section class="top-bar-section">
<?php //print zurb_foundation_links__topbar_main_menu($main_menu); ?>
    <?php print render($page['menu']);
    ?>
</section>

but the html structure that is printed is different to what I need. The following is what gets printed. As you can see its creating a new section with a list inside. I want to get that menu in the section that is currently empty (be aware that I'm printing it at the correct position in my tpl.). I also need to change its ID & CSS Classes.

<section class="top-bar-section"></section>
<section class="block block-system contextual-links-region block-menu block-system-main-menu">
        <ul class="menu">
             <li class="first collapsed"><a href="/rubelhp/lernumgebungen">Lernumgebungen</a></li>
             <li class="collapsed"><a href="/rubelhp/unterstuetzung">Unterstützung</a></li>
             <li class="collapsed"><a href="/rubelhp/foerderung">Förderung</a></li>
             <li class="collapsed"><a href="/rubelhp/projekte">Projekte</a></li>
             <li class="last collapsed"><a href="/rubelhp/kontakt">Kontakt</a></li>
        </ul>  
</section>

I want to avoid to call the menu directly instead of the region. The reason behind it is as I wrote in the beginning the visibility settings. The region contains menus that differ by the URL.

0

You can override the block template use by your position (block--menu.tpl.php) directly in your theme folder. By default, the render of your menu must use block.tpl.php from the block module.

I recommend you to have a look at the Working with template suggestions page, and to enable the Theme debug mode to see witch template are used for your block menu.

After, to modify the Classes and the ID of your menu, I recommend you to work with template_preprocess_block hook to modify the block object before the render print it.

You can also have a look at the theme_menu_tree hook, to be able to modify a wrapper of the menu tree, depending on conditions (menu names). There is also a THEMENAME_menu_tree__MENU_NAME possible method, that work only for one specific menu.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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