0

I installed the Menu block module, and it seems to work fine.

I need to change one of the menu HTML output; instead of the following HTML tags:

<ul class="menu">
  <li><a href="/" title="">Home</a></li>
  <li><a href="/our-rides" title="">Our Rides</a></li>
</ul>

I want to have:

<a href="/" title="">Home</a>|<a href="/our-rides" title="">Our Rides</a>

I tried implementing a hook, but it doesn't work.

function bsrentals_menu_item_link__menu_block($variables) {
      print 123;exit;
}
2

Well, what you want to achieve ... Eg, output a horizontal list of links with "pipes" between them can be done in Drupal with the HTML and CSS drupal provides you.

What you need to refer to is a book on CSS.

A random Google of this technique yields: http://jamesowers.co.uk/css-tutorials/50/horizontal-css-list-menu/

In a nutshell, you want to set the list-item as relative and to display inline in CSS. Give them some spacing and for instance add a right-border to every list item with your color choice. Then if you really want using a CSS/Jquery selector of :last-child remove the trailing right border if it bothers you.

If you are intent on rewriting and bending the HTML and CSS to your will because the above approach elludes you .... you can do 1 of 2 options:

1) using the http://drupal.org/project/devel_themer you can find the specific block in question within your theme. You can then alter the necessary template file(s) in drupal to alter the HTML produced from Drupal to meet your criteria. Menus are shown in blocks on the page. So you could find the theme function for the menu in question and override its output in your theme. Devel_theme should be able to tell you the correct function to override if your's isn't working.

Or you could create a really silly function like below in your template.php file and call it as needed from your .tpl files. The below code relies on the http://api.drupal.org/api/drupal/includes--menu.inc/function/menu_tree_all_data/7 function to pull a menu's items by the menu-name. See the linked API page to find out how to find out what specific menu in drupal you want to load ... then we simply create the HTML from the menu links as in the function. I really really dont recommend you do this. Either learn CSS and Jquery to render the default content drupal provides you with to appear as you want, or learn how to change the template files gracefully ...

/*
What does menu_tree_all_data() return ... well let's see below:

$ drush eval 'print_r(menu_tree_all_data("main-menu"));'Array
(
[49950 Home 240] => Array
    (
        [link] => Array
            (
                [menu_name] => main-menu
                [mlid] => 240
                [plid] => 0
                [link_path] => <front>
                [router_path] =>
                [link_title] => Home
                [options] => Array
                    (
                        [attributes] => Array
                            (
                                [title] =>
                            )

                    )

                [module] => menu
                [hidden] => 0
                [external] => 1
                [has_children] => 0
                [expanded] => 0
                [weight] => -50
                [depth] => 1
                [customized] => 1
                [p1] => 240
                [p2] => 0
                [p3] => 0
                [p4] => 0
                [p5] => 0
                [p6] => 0
                [p7] => 0
                [p8] => 0
                [p9] => 0
                [updated] => 0
                [load_functions] =>
                [to_arg_functions] =>
                [access_callback] =>
                [access_arguments] =>
                [page_callback] =>
                [page_arguments] =>
                [delivery_callback] =>
                [tab_parent] =>
                [tab_root] =>
                [title] => Home
                [title_callback] =>
                [title_arguments] =>
                [theme_callback] =>
                [theme_arguments] =>
                [type] =>
                [description] =>
                [in_active_trail] =>
                [access] => 1
                [href] => <front>
                [localized_options] => Array
                    (
                        [attributes] => Array
                            (
                                [title] =>
                            )

                    )

            )

        [below] => Array
            (
            )

    )

[49951 Student Login 239] => Array
    (
        [link] => Array
            (
                [menu_name] => main-menu
                [mlid] => 239
                [plid] => 0
                [link_path] => student/login
                [router_path] => student/login
                [link_title] => Student Login
                [options] => Array
                    (
                        [attributes] => Array
                            (
                                [title] =>
                            )

                    )

                [module] => menu
                [hidden] => 0
                [external] => 0
                [has_children] => 0
                [expanded] => 0
                [weight] => -49
                [depth] => 1
                [customized] => 1
                [p1] => 239
                [p2] => 0
                [p3] => 0
                [p4] => 0
                [p5] => 0
                [p6] => 0
                [p7] => 0
                [p8] => 0
                [p9] => 0
                [updated] => 0
                [load_functions] =>
                [to_arg_functions] =>
                [access_callback] => 1
                [access_arguments] => a:0:{}
                [page_callback] => _dew_auth_login_page
                [page_arguments] => a:0:{}
                [delivery_callback] =>
                [tab_parent] =>
                [tab_root] => student/login
                [title] => Student Login
                [title_callback] => t
                [title_arguments] =>
                [theme_callback] =>
                [theme_arguments] => a:0:{}
                [type] => 6
                [description] =>
                [in_active_trail] =>
                [href] => student/login
                [access] => 1
                [localized_options] => Array
                    (
                        [attributes] => Array
                            (
                                [title] =>
                            )

                    )

            )

        [below] => Array
            (
            )

    )

)

*/

function i_dont_advise_this($menu_name) {
  $data = menu_tree_all_data($menu_name);
  $links = array();

  foreach($data as $MenuItem => $item) {
    $links []= l($item['link']['title'], $item['link']['link_path']);
  }
  return implode('|', $links);
}

print i_dont_advise_this('main-menu');
# yields =>
# <a href="/" class="active">Home</a>|<a href="/?q=student/login">Student Login</a>
| improve this answer | |
  • 1. Your css/jquery idea doesn't seem good to me. What's the use of creating a code and then removing it via css/jquery? It's better to generate <a> tags without <ul>. – usr345 Nov 2 '11 at 18:56
0

Check out this module: https://github.com/Moonfuse/drupal-nav .

It's a simple little module I wrote to customize your menu's HTML by writing HTML.

You can also preprocess the menu items via hook_drupalnav.

| improve this answer | |

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.