Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4031504
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T11:36:20+00:00 2026-05-20T11:36:20+00:00

Can someone please help me out, I’m totally stuck! I don’t know how to

  • 0

Can someone please help me out, I’m totally stuck! I don’t know how to add a class name to <li> tag in Zend navigation XML

This is my XML

<configdata>
    <nav>
        <home>
            <label>Home </label>
            <uri>/</uri> 
        </home>

        <request>
            <label>Quotes </label>
            <uri>/quote</uri>
        </request>

        <work>
            <label>How It Works</label>
            <uri>/how-it-works</uri>
        </work>

        <information>
            <label>Informations </label>
            <uri>/informations</uri>
        </information>

        <directory>
            <class> last </class>
            <label>Directory </label>
            <uri>/directory</uri>  
        </directory>
    </nav>
</configdata>

When I add <class>last</class> this is what i get:

<li>
    <a class="last" href="/directory">Directory </a>
</li>

Currently I’m getting <a class="last"> but I need <li class="last">

Thanks so much in advance!
Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T11:36:21+00:00Added an answer on May 20, 2026 at 11:36 am

    I think that the best way to put css classes into li elements would be to write your own navigation menu helper, called for example My_View_Helper_NavigationMenu that extends original Zend_View_Helper_Navigation_Menu class. For this reason I prepared an example of such a helper that overloads _renderMenu() method. The code of the method seems long, but this is because original code is long. There are only few new/modified lines in overloaded _renderMenu():

    File: APPLICATION_PATH/views/helpers/NavigationMenu.php

    class My_View_Helper_NavigationMenu extends Zend_View_Helper_Navigation_Menu { 
    
         /**
         * Renders a normal menu (called from {@link renderMenu()})
         *
         * @param  Zend_Navigation_Container $container   container to render
         * @param  string                    $ulClass     CSS class for first UL
         * @param  string                    $indent      initial indentation
         * @param  int|null                  $minDepth    minimum depth
         * @param  int|null                  $maxDepth    maximum depth
         * @param  bool                      $onlyActive  render only active branch?
         * @return string
         */
        protected function _renderMenu(Zend_Navigation_Container $container,
                                       $ulClass,
                                       $indent,
                                       $minDepth,
                                       $maxDepth,
                                       $onlyActive)
        {
            $html = '';
    
            // find deepest active
            if ($found = $this->findActive($container, $minDepth, $maxDepth)) {
                $foundPage = $found['page'];
                $foundDepth = $found['depth'];
            } else {
                $foundPage = null;
            }
    
            // create iterator
            $iterator = new RecursiveIteratorIterator($container,
                                RecursiveIteratorIterator::SELF_FIRST);
            if (is_int($maxDepth)) {
                $iterator->setMaxDepth($maxDepth);
            }
    
            // iterate container
            $prevDepth = -1;
            foreach ($iterator as $page) {
                $depth = $iterator->getDepth();
                $isActive = $page->isActive(true);
                if ($depth < $minDepth || !$this->accept($page)) {
                    // page is below minDepth or not accepted by acl/visibilty
                    continue;
                } else if ($onlyActive && !$isActive) {
                    // page is not active itself, but might be in the active branch
                    $accept = false;
                    if ($foundPage) {
                        if ($foundPage->hasPage($page)) {
                            // accept if page is a direct child of the active page
                            $accept = true;
                        } else if ($foundPage->getParent()->hasPage($page)) {
                            // page is a sibling of the active page...
                            if (!$foundPage->hasPages() ||
                                is_int($maxDepth) && $foundDepth + 1 > $maxDepth) {
                                // accept if active page has no children, or the
                                // children are too deep to be rendered
                                $accept = true;
                            }
                        }
                    }
    
                    if (!$accept) {
                        continue;
                    }
                }
    
                // make sure indentation is correct
                $depth -= $minDepth;
                $myIndent = $indent . str_repeat('        ', $depth);
    
                if ($depth > $prevDepth) {
                    // start new ul tag
                    if ($ulClass && $depth ==  0) {
                        $ulClass = ' class="' . $ulClass . '"';
                    } else {
                        $ulClass = '';
                    }
                    $html .= $myIndent . '<ul' . $ulClass . '>' . self::EOL;
                } else if ($prevDepth > $depth) {
                    // close li/ul tags until we're at current depth
                    for ($i = $prevDepth; $i > $depth; $i--) {
                        $ind = $indent . str_repeat('        ', $i);
                        $html .= $ind . '    </li>' . self::EOL;
                        $html .= $ind . '</ul>' . self::EOL;
                    }
                    // close previous li tag
                    $html .= $myIndent . '    </li>' . self::EOL;
                } else {
                    // close previous li tag
                    $html .= $myIndent . '    </li>' . self::EOL;
                }
    
    
    
    
    
    
    
    
                // ***************** THESE ARE NEW LINES *************** //
                $liMyClass = $page->get('liclass') ? $page->liclass : '' ;
    
                if ($isActive) {
                    $liClass = " class=\"active $liMyClass\" ";
                } else {
                    $liClass = $liMyClass ? " class=\"$liMyClass\" ":'';
                }
    
                // ***************** END OF NEW STUFF *************** //
    
                // render li tag and page (ORGINAL LINE REMOVED)
                //$liClass = $isActive ? ' class="active "' : '';      
    
    
    
    
    
    
    
    
    
                $html .= $myIndent . '    <li' . $liClass . '>' . self::EOL
                       . $myIndent . '        ' . $this->htmlify($page) . self::EOL;
    
                // store as previous depth for next iteration
                $prevDepth = $depth;
            }
    
            if ($html) {
                // done iterating container; close open ul/li tags
                for ($i = $prevDepth+1; $i > 0; $i--) {
                    $myIndent = $indent . str_repeat('        ', $i-1);
                    $html .= $myIndent . '    </li>' . self::EOL
                           . $myIndent . '</ul>' . self::EOL;
                }
                $html = rtrim($html, self::EOL);
            }
    
            return $html;
        }
    }
    

    In your layout.phtml you need to indicate to the navigation view helper to use this new class. You can do this as follows:

    <?php  $this->navigation()->setDefaultProxy('navigationMenu'); ?>;
    

    Finally in your navigation.xml you could define a class for a li element using liclass tag (you can use whatever name you want for this tag):

    <directory>
        <class> last </class>
        <label>Directory </label>
        <uri>/directory</uri>
        <liclass>someclass</liclass>
    </directory>
    

    Hopefully this will be helpful to you. Ideally, I should have named the new class My_View_Helper_Navigation_Menu (located in APPLICATION_PATH/views/helpers/Navigation/Menu.php). However, I could not make Zend plugin loaders to load it and I went with My_View_Helper_NavigationMenu.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please help me out with printing the contents of an IFrame via
Can someone please help me out with a JavaScript/jQuery solution for this arithmetic problem:
Can someone please help me figure out why my accordion script at http://www.mincovlaw.com/services/copyright gets
Can someone please help me figure out a way to achieve the following (see
Can someone please help me out? My code for splitting the strings is working
Can someone please help me out with this? I'm using jquery-1.4.2. http://jsfiddle.net/Ymkpb/ Thank you
Can someone please help me out... I've tried all kinds of things (including help
Can someone please help me out with this scenario asap? Input XML: <dataXML> <Items>
Can someone please help me out, I am just getting into Spring3, Spring3 MVC
Can someone please help me figure out what I'm doing wrong? I have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.