Specifying CSS class of a Zend_Navigation li element

delete your code, development, php, zend Add comments

Zend Navigation is a really nice tool to handle menus.

You just specify an array of your menu items:

$pages = array(
    array(
        'label'      => 'Privacy Statement',
        'controller' => 'terms',
        'action'     => 'privacy-statement',
        'class'      => 'firstNav',
    ),
    array(
        'label'      => 'General Terms of Use',
        'controller' => 'terms',
        'action'     => 'general-terms-of-use',
    ),
);

and initialize the navigation object with it — and it works:

$container = new Zend_Navigation($pages);
$this->view->navigation($container)->menu()
    ->setUlClass('nav')
    ->setActiveClass('active');

Result is the following:

<ul class="nav">
    <li class="active">
        <a class="firstNav" href="/terms/privacy-statement">Privacy Statement</a>
    </li>
    <li>
        <a href="/terms/general-terms-of-use">General Terms of Use</a>
    </li>
</ul>

There are options to specify the CSS class of the whole UL tag. If you specify CSS of a menu item (“firstNav” in my example), it’s added to to the A tag, not the LI tag as required by sliced design I have.

Googling shows that people are trying to work-around that by jQuery fixes.

It seems there is a proper way to solve this; you just need to add this option:

$this->view->navigation()->menu()->addPageClassToLi(true);

Enjoy!

Comments are closed.

WP Theme & Icons by N.Design Studio
Entries RSS Comments RSS Log in