ioMenuPlugin - 0.6.0

A plugin to make menus easier to write in symfony.

You are currently browsing
the website for symfony 1

Visit the Symfony2 website


« Back to the Plugins Home

Signin


Forgot your password?
Create an account

Tools

Stats

advanced search
Information Readme Releases Changelog Contribute
Show source

ioMenuPlugin

A plugin to make menus easier to write in symfony.

  • Current menu item automatically given active class
  • Menu items automatically given first and last classes
  • Show/hide menus based on authentication, credentials
  • Hide portions of the tree, or render down to a certain depth
  • Menu rendered with "pretty" spacing for easier debugging & styling

Inspired by sympal and the SemanticMenu from Ruby on Rails.

Usage

Assume any of the routes have been defined in routing.yml:

$menu = new ioMenu();
$menu->addChild('overview', '@homepage');
$menu->addChild('comments', '@comments');
echo $menu->render();

Assuming you are on /comments, the output would be:

<ul class="menu">
  <li class="first">
    <a href="/">overview</a>
  </li>
  <li class="current last">
    <a href="/comments">comments</a>
  </li>
</ul>

The ioMenu class optionally takes an array of attributes as its first argument. You can also nest menus as deeply as you want:

$menu = new ioMenu(array('class' => 'top_level_nav'));
$menu->addChild('overview', '@homepage');
$menu->addChild('comments', '@comments', array('class' => 'button'));
  $menu['comments']->addChild('My Comments', '@my_comments');
  $menu['comments']->addChild('Recent', '@recent_comments');

echo $menu->render();

Assuming you're in the /my-comments page, the output would be:

<ul class="top_level_nav">
  <li class="first">
    <a href="/">overview</a>
  </li>
  <li class="button current_ancestor last">
    <a href="/comments">comments</a>
    <ul class="menu_level_1">
      <li class="current first">
        <a href="/my-comments">My Comments</a>
      </li>
      <li class="last">
        <a href="/recent">Recent</a>
      </li>
    </ul>
  </li>
</ul>