CodeIgniter Forums
html helper: ul() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: html helper: ul() (/thread-5979.html)

Pages: 1 2


html helper: ul() - El Forum - 02-10-2008

[eluser]fdog[/eluser]
I want to generate an ul using the HTML helper. I need to add a class attribute to an li.

desired output:
Code:
<ul>
    <li class="current_page_item">
        <a href="#">home</a>
    </li>
    <li>
        <a href="#">photos</a>
    </li>
    <li>
        <a href="#">about</a>
    </li>
</ul>

current controller:
Code:
$menu = array(
          'home',
          'photos',
          'about',
         );

$attributes = array(
                    'class' => 'current_page_item'
                   );

Is there a way to pass $attributes to a li instead of the whole ul?


html helper: ul() - El Forum - 02-10-2008

[eluser]Derek Allard[/eluser]
No, there's no way to add attributes to an li unfortunately.


html helper: ul() - El Forum - 02-10-2008

[eluser]Référencement Google[/eluser]
I think it would be good to have this feature Derek, building dynamic menus is the only purpose I can personally find to the html list helper, so it would be good that we can pass to it some attributes.


html helper: ul() - El Forum - 02-10-2008

[eluser]Derek Allard[/eluser]
I don't object to that at all. You want to take a stab at a revised ul() function?


html helper: ul() - El Forum - 02-10-2008

[eluser]Référencement Google[/eluser]
Sorry, my english level do not permit me to understand the word "stab". Do you propose to me that I make this revised function?


html helper: ul() - El Forum - 02-10-2008

[eluser]Derek Allard[/eluser]
I apologize for using slang. Yes, would you like to try making a revised function?


html helper: ul() - El Forum - 02-10-2008

[eluser]Référencement Google[/eluser]
Ok, why not. I can't make that now but I will take a look at it tomorrow (for my local time it means in about 12 hours) Then I will post it here.


html helper: ul() - El Forum - 02-10-2008

[eluser]fdog[/eluser]
Can't wait! :lol:


html helper: ul() - El Forum - 02-10-2008

[eluser]Référencement Google[/eluser]
hmmm... Derek, looking at the code it seems already possible to pass attributes.

The ul function:
Code:
function ul($list, $attributes = '')
{
    return _list('ul', $list, $attributes);
}

The _list function parameters called by the ul function:
Code:
function _list($type = 'ul', $list, $attributes = '', $depth = 0)

Can you confirm it please?


html helper: ul() - El Forum - 02-10-2008

[eluser]Derek Allard[/eluser]
You can add them to the <ul>, but fdog's request was to have them added to the <li>.