XF 2.2 Looping through a foreach and counting the results

Lee

Well-known member
If I have the following code:

Code:
<xf:foreach loop="$foobar" value="$foo">
</xf:foreach>

Is it possible to cumulatively check the value of a result and check to see if it is not null?

For example if I had 10 results I would like to read the following field:

Code:
$foo.xyz

And display some text if any of them return null.
 

Lawrence

Well-known member
If I have the following code:

Code:
<xf:foreach loop="$foobar" value="$foo">
</xf:foreach>

Is it possible to cumulatively check the value of a result and check to see if it is not null?

For example if I had 10 results I would like to read the following field:

Code:
$foo.xyz

And display some text if any of them return null.

HTML:
<xf:foreach loop="$foobar" value="$foo">
    <xf:if is="$foo">
        Has a value
    <xf:else />
        value is null, empty, or possibly 0
    </xf:if>
</xf:foreach>
 
  • Like
Reactions: Lee

Lawrence

Well-known member
Would that work if there were instances were $foo.xyz was 1 and instances were it were 0?
The above will work with 0 in a template (I believe it is treated as a string and not a number). To test explicitly for a 0 or a 1:

HTML:
<xf:if is="$foo == '0' OR $foo == '1'">

<xf:else />

</xf:if>
 
Top