Need example

I see that the "styles" parameter is included in the menu class. It says it is a nested array, but there is no documentation of what its structure is to be.

I will be using code similar to
<?php echo fuel_nav(array('container_tag_id' => 'topmenu', 'item_id_prefix' => 'topmenu_')); ?>

I have a 2-level menu that needs a specific class on every

element...
It needs the same class both in the main menu bar and in the dropdowns.

Can you give me an example of how FUEL wants that styles array structured?

Thank you

Comments

  • sorry -- my tag got stripped. It needs to be on every li

  • The index of the styles array indicates the nested depth to apply the styles:

    <?php echo fuel_nav(array('container_tag_id' => 'topmenu', 'item_id_prefix' => 'topmenu_', 'styles' => array( 0 => 'level1', 1 => 'level2'))); ?>
    
  • Thank you. That helps a lot.

  • The index of the styles array indicates the nested depth to apply the styles

    In the example you gave, Is there a way to only apply the level1 style to the parent li that has sub menus?

    For example:

    View:
    <nav class="nav-menu d-none d-lg-block"> <?=fuel_nav(array('container_tag_class' => 'nav nav-tabs', 'subcontainer_tag_class' => array(0 => ''), 'styles' => array( 0 => 'drop-down', 1 => '')));?> </nav>

    Desired Output:
    <ul class="nav nav-tabs"> <li class="first active"><a href="http://localhost/Home">Home</a></li> <li><a href="http://localhost/Home/About">About</a></li> <li class=**"drop-down"**><a href="http://localhost/Home/Services">Services</a> <ul> <li class="first"><a href="http://localhost/Home/services/internet">Internet Service</a></li> <li class="last"><a href="http://localhost/Home/services/phone">Phone/Voice Services</a></li> </ul> </li> <li><a href="http://localhost/Home/Pricing">Pricing</a></li> <li class="last"><a href="http://localhost/Home/Contact">Contact</a></li> </ul>

  • You can do nested, nested arrays too:

    <?php echo fuel_nav(array('container_tag_id' => 'topmenu', 'item_id_prefix' => 'topmenu_', 'styles' => array( 0 => 'level1', 1 => array(0 => 'level2')))); ?>
    
  • edited March 2023

    You sir are a rockstar! This brought me a lot closer, but I still need some assistance. In my use-case I am trying to specify an li class but only for parent nav records that have child records. In this screenshot as an example, it would be the highlighted class because this is the only parent record that has child navigation records. Is this possible?

    https://www.filesharing.com/download/LA5EzdYV7mWs8FIKqZNU

  • You may need to essentially pre-process the navigation items to determine the styles parameter values. You can get the navigation in an array structure by using render_type => 'array'. Then you can loop through the data and create an styles array that works for your needs.

    $array_data = fuel_nav(array('render_type' => 'array')
    
Sign In or Register to comment.