Two IF blocks inside foreach, second IF gets lost

Author Message

Xavier Serna

Friday 29 December 2006 4:43:05 am

Hi all,

I've a very strange problem. I have a foreach block, and inside it, I put two IF blocks to print out diferent content depending on various conditions. Well, the second IF block is never executed, as if it was never there. Any idea about this?

Here is the problematic code:

{foreach $list_items as $index => $child}
    <li {if eq($module_result.section_id,$child.object.section_id)}
            class="selected"
        {/if}
        {if eq($index,4)}
            class="last"
        {/if} ><a href={$child.url_alias|ezurl}>{$child.name|wash()}</a></li>				
{/foreach}		

For any reason the second IF is always ignored. If I reverse the order it does the same thing, executes the first one (prints result if the condition is true) but the second gets ignored.

Any help would be appreciated.
Thanks in advance!

--
Xavier Serna
eZ Publish Certified Developer
Departament de Software
Microblau S.L. - http://www.microblau.net
+34 937 466 205

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

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:23:41
Script start
Timing: Jan 18 2025 18:23:41
Module start 'layout'
Timing: Jan 18 2025 18:23:41
Module start 'content'
Timing: Jan 18 2025 18:23:42
Module end 'content'
Timing: Jan 18 2025 18:23:42
Script end

Main resources:

Total runtime0.6447 sec
Peak memory usage4,096.0000 KB
Database Queries54

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0061 589.1641152.6406
Module start 'layout' 0.00610.0028 741.804739.4766
Module start 'content' 0.00890.6341 781.2813527.5938
Module end 'content' 0.64310.0016 1,308.875012.1250
Script end 0.6447  1,321.0000 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00340.5198160.0002
Check MTime0.00130.2053160.0001
Mysql Total
Database connection0.00120.190310.0012
Mysqli_queries0.595392.3407540.0110
Looping result0.00050.0800520.0000
Template Total0.608194.320.3041
Template load0.00200.308320.0010
Template processing0.606194.012520.3031
Template load and register function0.00020.032210.0002
states
state_id_array0.00150.238210.0015
state_identifier_array0.00190.293420.0009
Override
Cache load0.00160.2472200.0001
Sytem overhead
Fetch class attribute can translate value0.00100.151120.0005
Fetch class attribute name0.00110.171730.0004
XML
Image XML parsing0.00260.405120.0013
class_abstraction
Instantiating content class attribute0.00000.001030.0000
General
dbfile0.00270.4170160.0002
String conversion0.00000.001140.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
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
2content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
6content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
3content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 15
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs