Forums / Setup & design / Automatic class assignment

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...

eZ debug

Timing: Jan 31 2025 00:41:14
Script start
Timing: Jan 31 2025 00:41:14
Module start 'content'
Timing: Jan 31 2025 00:41:14
Module end 'content'
Timing: Jan 31 2025 00:41:14
Script end

Main resources:

Total runtime0.1811 sec
Peak memory usage8,192.0000 KB
Database Queries141

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0075 587.9297370.2969
Module start 'content' 0.00750.0137 958.22661,001.5469
Module end 'content' 0.02120.1598 1,959.77343,890.4375
Script end 0.1810  5,850.2109 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00432.3990200.0002
Check MTime0.00130.7408200.0001
Mysql Total
Database connection0.00060.314810.0006
Mysqli_queries0.090449.91731410.0006
Looping result0.00130.72541390.0000
Template Total0.159488.010.1594
Template load0.00080.467710.0008
Template processing0.158587.536010.1585
Override
Cache load0.00060.319210.0006
Sytem overhead
Fetch class attribute can translate value0.00180.970410.0018
XML
Image XML parsing0.00020.125310.0002
General
dbfile0.00683.7440200.0003
String conversion0.00000.004330.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/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