Share » Forums » Developer » Two IF blocks inside foreach, second...

Two IF blocks inside foreach, second IF gets lost

Two IF blocks inside foreach, second IF gets lost

Friday 29 December 2006 4:43:05 am - 1 reply

Author Message

Claudia Kosny

Friday 29 December 2006 2:37:09 pm

Hi Xavier

I have tried a simplified version in both EZ 3.8.3 and Ez 3.9 and it is working as expected:

{def $foo = array('a', 'b', 'c', 'd')}
{foreach $foo as $key=>$value}
  {if $value|eq('b')}
    should be true for value b <br />
  {/if}
  {if $key|eq(1)}
    should be true for key 1 <br />
  {/if}
  key: {$key} <br />
  value: {$value} <br /><br />
{/foreach}

Looking at your code I assume that you don't have a problem with the two IF's, but with having two classes for one item. If both if-conditions evaluate to true, the result of your loop will look like this:

<li class="selected" class="last"><a href="...

This is invalid html as you can have only one class attribute and most browsers will consider only the first class attribute. This might give the wrong impression that the second if is ignored. So change your code so you get a class="selected last" if both conditions are true and you should be done.

Claudia

Claudia

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

36 542 Users on board!

Forums menu