eZ Community » Forums » Setup & design » If-then-elseif/case; Is there a...
expandshrink

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

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

Thursday 20 November 2003 11:09:01 am - 2 replies

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}

Thursday 20 November 2003 11: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}

Thursday 20 November 2003 1:15:52 pm

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

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from