Skip to content

Instantly share code, notes, and snippets.

@eugene-ilyin
Last active October 26, 2017 23:47
Show Gist options
  • Save eugene-ilyin/e87d6242220b076f4675 to your computer and use it in GitHub Desktop.
Save eugene-ilyin/e87d6242220b076f4675 to your computer and use it in GitHub Desktop.
Render menu programmatically in Drupal 7
// One level menu.
$menu = menu_tree('main-menu');
$menu_items = render($menu);
// Menu with many levels.
menu_tree_all_data('main-menu');
$menu = menu_build_tree('main-menu');
$menu_items = render(menu_tree_output($menu));
@franciscocorrales
Copy link

franciscocorrales commented Jan 19, 2017

What if I want to add custom HTML ?, is there a way to go through the elements (links) ?

Example HTML:

    <div class="col-xs-6">
      <ul>
        <li>no link</li>
        <li class="class"><a href=""></a>link 1</li>
        <li class="class"><a href=""></a>link 2</li>
      </ul>
    </div>
    <div class="col-xs-6">
      <ul>
        <li class="class"><a href=""></a>link 3</li>
        <li class="class2"><a href=""></a>link 4</li>
      </ul>
    </div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment