If-then-elseif/case; Is there a better way in ez

Author Message

Tristan Koen

Thursday 20 November 2003 2:09:01 am

I have a small control structure that I have written in the ez templating language that is incredibly cumbersome (see below). Can anyone suggest a better way to do this?
All it is supposed to do is show an image of start (rating) for different values of user ratings.

---------------------------
{section show=$:item.Rating|gt(4.75)}
<img src={"stars-5-0.gif"|ezimage} alt="Rating: {$:item.Rating}" border="0" />
{section-else}
{section show=$:item.Rating|gt(4.25)}
<img src={"stars-4-5.gif"|ezimage} alt="Rating: {$:item.Rating}" border="0" />
{section-else}
{section show=$:item.Rating|gt(3.75)}
<img src={"stars-4-0.gif"|ezimage} alt="Rating: {$:item.Rating}" border="0" />
{section-else}
{section show=$:item.Rating|gt(3.25)}
<img src={"stars-3-5.gif"|ezimage} alt="Rating: {$:item.Rating}" border="0" />
{section-else}
{section show=$:item.Rating|gt(2.75)}
<img src={"stars-3-0.gif"|ezimage} alt="Rating: {$:item.Rating}" border="0" />
{section-else}
{section show=$:item.Rating|gt(2.25)}
<img src={"stars-2-5.gif"|ezimage} alt="Rating: {$:item.Rating}" border="0" />
{section-else}
{section show=$:item.Rating|gt(1.75)}
<img src={"stars-2-0.gif"|ezimage} alt="Rating: {$:item.Rating}" border="0" />
{section-else}
{section show=$:item.Rating|gt(1.25)}
<img src={"stars-1-5.gif"|ezimage} alt="Rating: {$:item.Rating}" border="0" />
{section-else}
{section show=$:item.Rating|gt(0.75)}
<img src={"stars-1-0.gif"|ezimage} alt="Rating: {$:item.Rating}" border="0" />
{section-else}
<img src={"stars-0-0.gif"|ezimage} alt="Rating: {$:item.Rating}" border="0" />
{/section}
{/section}
{/section}
{/section}
{/section}
{/section}
{/section}
{/section}
{/section}

Tore Skobba

Thursday 20 November 2003 2:30:14 am

Hmm switch/case ?

Like
{switch match=$:item.Rating}
{case match=gt(1.25)}
do some stuff
{/case}
{case match=gt(2.35)}
do some stuff
{/case}
{/switch}

Tristan Koen

Thursday 20 November 2003 4:15:52 am

Yes... thats exactly what I was looking for. I must have missed it in the docs.
Thanks very much for the help.

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 18 2025 18:36:52
Script start
Timing: Jan 18 2025 18:36:52
Module start 'layout'
Timing: Jan 18 2025 18:36:52
Module start 'content'
Timing: Jan 18 2025 18:36:53
Module end 'content'
Timing: Jan 18 2025 18:36:53
Script end

Main resources:

Total runtime1.2454 sec
Peak memory usage4,096.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0052 588.0469152.6406
Module start 'layout' 0.00520.0026 740.687539.4922
Module start 'content' 0.00781.2358 780.1797478.2813
Module end 'content' 1.24360.0017 1,258.460912.1250
Script end 1.2453  1,270.5859 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.2806160.0002
Check MTime0.00130.1082160.0001
Mysql Total
Database connection0.00090.069410.0009
Mysqli_queries1.171294.0415570.0205
Looping result0.00100.0800550.0000
Template Total1.210397.220.6051
Template load0.00220.175220.0011
Template processing1.208197.005620.6041
Template load and register function0.00050.039110.0005
states
state_id_array0.00140.111010.0014
state_identifier_array0.00160.128020.0008
Override
Cache load0.00190.1554570.0000
Sytem overhead
Fetch class attribute can translate value0.00150.121520.0008
Fetch class attribute name0.00180.147730.0006
XML
Image XML parsing0.00030.024820.0002
class_abstraction
Instantiating content class attribute0.00000.000730.0000
General
dbfile0.00060.0499100.0001
String conversion0.00000.000640.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
4content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 14
 Number of unique templates used: 5

Time used to render debug report: 0.0001 secs