XF 2.1 Incrementing counter inside loop of a template?


Active member
This seems easy but for the life of me I'm unable to get it to work.

I've an array inside of an array and after both have been looped, I'm trying to get the total count of items iterated. Something like this:

<xf:set var="$total">0</xf:set>
<xf:foreach loop="$foo" value="$child_array" i="$parent_count"> 
    <xf:foreach loop="$child_array" i="$child_count">
        <xf:set var="$total">{{$total + 1}}</xf:set>

And to give a sample structure of $foo:
array:4 [▼
  "foo1" => array:5 [▶]
  "foo2" => array:5 [▶]
  "foo3" => array:1 [▶]
  "foo4" => array:4 [▶]

So ideally, the end result should be 15 but I'm getting it as 2.

What I'm missing here?
Last edited: