Welcome Guest, Not a member yet? Register   Sign In
html helper: ul()
#1

[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?
#2

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

[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.
#4

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

[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?
#6

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

[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.
#8

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

[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?
#10

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




Theme © iAndrew 2016 - Forum software by © MyBB