XF 2.0 Is there a xen:calc equivalent in XF2

AndyB

Well-known member
In XF1 we were able to use template code like this:

PHP:
<xen:set var="$i">0</xen:set>

<xen:foreach loop="$posts" value="$post">
<tr class="dataRow">

<xen:set var="$j">{$i}</xen:set>
<td><xen:set var="$i">{xen:calc '{$j}+1'}</xen:set>{$i}</td>

Is there any way to do similar in XF2?
 
Thank you, Chris.

I tried this:

HTML:
        <xf:foreach loop="$listDays" value="$listday">

            {{ $j + 1 }}

            {$j}
...

I was expecting $j to increment, but it just stays at 1.
 
Well, you'd still have to set it as before. I was just telling you the equivalent of the {xen:calc} bit.
 
This just get an output of 2 0 over and over again. I would like an output of 12345 etc...

HTML:
        <xf:set var="$j">0</xf:set>
            
        <xf:foreach loop="$listDays" value="$listday">

            {{ $j + 1 }}

            {$j}
...
 
I only provided you the bit to replace the {xen:calc} function specifically. You still have to use <xf:set>!
 
The following just outputs 2 over and over again.

PHP:
        <xf:set var="$i">0</xf:set>
            
        <xf:foreach loop="$listDays" value="$listday">
            
            <xf:set var="$j">{$i}</xf:set>
            <xf:set var="$i">{{ $j + 1 }}</xf:set>{$i}
...
 
Code:
<xf:set var="$j">0</xf:set>
FOR EACH LOOP
Code:
 <xf:if is="{$result.is_banned} > 0">
            <s>{$result.username}</s>
        <xf:else />
            <xf:set var="$j">{{ $j + 1 }}</xf:set>
            {$result.username}</xf:if>
LOOP
OUTPUT $j

What if not counting the number of iterations, but trying to count a separate variable that increments based on a conditional in the loop? Trying something similar to what @AndyB has posted by setting the variable to 0 before the loop and then +1 inside the conditional but it's not counting right.
 
<xen:foreach loop="$content" key="$key" value="$val" >
{{$key}} :: {{$val}}
</xen:foreach>

Does not work for me. Any idea, please?
 
Last edited:
Back
Top Bottom