• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 2.0 Is there a xen:calc equivalent in XF2

AndyB

Well-known member
#1
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?
 

AndyB

Well-known member
#3
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.
 

Chris D

XenForo developer
Staff member
#4
Well, you'd still have to set it as before. I was just telling you the equivalent of the {xen:calc} bit.
 

AndyB

Well-known member
#5
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}
...
 

Chris D

XenForo developer
Staff member
#6
I only provided you the bit to replace the {xen:calc} function specifically. You still have to use <xf:set>!
 

AndyB

Well-known member
#7
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}
...
 

Chris D

XenForo developer
Staff member
#8
Probably a moot point anyway, if you just want a counter to increment the the number of iterations which have been performed, we've had a feature built in for that since XF 1.

HTML:
<xf:foreach loop="$listDays" value="$listday" i="$i">
    {$i}
</xf:foreach>