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.

eZ debug

Timing: Jan 31 2025 00:24:46
Script start
Timing: Jan 31 2025 00:24:46
Module start 'layout'
Timing: Jan 31 2025 00:24:46
Module start 'content'
Timing: Jan 31 2025 00:24:46
Module end 'content'
Timing: Jan 31 2025 00:24:46
Script end

Main resources:

Total runtime0.0412 sec
Peak memory usage6,144.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0056 588.1328151.2109
Module start 'layout' 0.00560.0039 739.3438220.6875
Module start 'content' 0.00940.0301 960.0313997.8203
Module end 'content' 0.03960.0016 1,957.851633.9922
Script end 0.0411  1,991.8438 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00286.6867140.0002
Check MTime0.00112.7363140.0001
Mysql Total
Database connection0.00092.208610.0009
Mysqli_queries0.00255.983530.0008
Looping result0.00000.041110.0000
Template Total0.00112.710.0011
Template load0.00092.103810.0009
Template processing0.00020.583310.0002
Override
Cache load0.00061.498510.0006
General
dbfile0.013933.721280.0017
String conversion0.00000.026640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs