document how to integrate nice_menus with an existing menu

Created on 20 January 2012, over 12 years ago
Updated 2 May 2024, about 2 months ago

I think it's the most common use-case: integrate nice_menus with the top main-menu of an existing theme.
So, let's say we use a child theme of Bartik containing the bare minimum (only intended to override some properties).
The default Bartik page.tpl.php contains the following:

<?php if ($main_menu): ?>
      <div id="main-menu" class="navigation">
        <?php print theme('links__system_main_menu', array(
          'links' => $main_menu,
          'attributes' => array(
            'id' => 'main-menu-links',
            'class' => array('links', 'clearfix'),
          ),
          'heading' => array(
            'text' => t('Main menu'),
            'level' => 'h2',
            'class' => array('element-invisible'),
          ),
        )); ?>

where $main_menu comes from includes/theme.inc / template_preprocess_page() when it calls menu_main_menu().

  • First note: this function being called unconditionally, it would be a perf' penalty to make yet another call to retrieve the menu to get the children.
  • Second note: menu_main_menu() will call menu_navigation_links("main-menu") which only returns the 1st level entries (whatever second argument is passed...)

Let's forget the above note about performance for now,

  • The first step is to override the menu array; hook__preprocess_page(&$variables) setting $variables['main_menu'] may be a good candidate for this but... which function to use to retrieve a deeper but similar structure than what menu_main_menu() returns ? menu_tree() ?
  • The second step is to control <ul> (id and classes) and override <li> (classes), thus using the themable links__system_main_menu

But here seem to come big troubles of menu_tree() to replace menu_main_menu(), at least because rendering recursively the menu without control on the top level <ul> makes all of them getting the what is obviously wrong.
So, let's believe that menu_tree() is the good candidate, how to theme it ?
The problem is obviously that the structure it returns contains #theme_wrappers == menu_tree__main_menu whatever the <ul> depth is.
Can we try to change it so that the first level #theme_wrappers is a themable we can control ?

follow-up coming.

✨ Feature request
Status

Closed: outdated

Version

2.0

Component

Documentation

Created by

πŸ‡«πŸ‡·France drzraf

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024