Automatic class assignment

Author Message

Noicokuna Niemoge

Wednesday 03 June 2009 3:07:26 am

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?

Shiki soku ze ku...

André R.

Wednesday 03 June 2009 3:16:48 am

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

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

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Noicokuna Niemoge

Wednesday 03 June 2009 7:26:47 am

Thanks a lot :)

Shiki soku ze ku...

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.