This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Setup & design » Automatic class assignment
expandshrink

Automatic class assignment

Automatic class assignment

Wednesday 03 June 2009 12:07:26 pm - 2 replies

Hi;

I'd like to dive different css classes to each menu item automatically. I want to construct class names, eg. "lido1", "lido2", etc.

But when I put:

 {foreach $top_menu_items as $key => $item}     
{if $key}
{set $item_class = $item_class|append("lido",$key)}
{/if}

... it produces the output "lido 1", "lido 2" etc, which is invalid. Now I'm forced to write:

            {if $key|eq(1)}
                {set $item_class = $item_class|append("lido1")}
            {/if}
 
            {if $key|eq(2)}
                {set $item_class = $item_class|append("lido2")}
            {/if}
 
            {if $key|eq(3)}
                {set $item_class = $item_class|append("lido3")}
            {/if}
 
            {if $key|eq(4)}
                {set $item_class = $item_class|append("lido4")}
            {/if}
 
            {if $key|eq(5)}
                {set $item_class = $item_class|append("lido5")}
            {/if}
    

... Can it be done in a simplified way?

Wednesday 03 June 2009 12:16:48 pm

Instead of creating different array keys for the string and key, concat them first:

{set $item_class = $item_class|append(  concat("lido", $key ) )}

Wednesday 03 June 2009 4:26:47 pm

Thanks a lot happy.gif Emoticon

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from