Not a bug count attribute in foreach tag doesn't seem to work

Neilski

Active member
Affected version
2.1.4
I'm modifying the conversation_list_macros template, and have discovered that the count attribute doesn't seem to work.
This issue was first reported by someone else back in September 2018 (here).

Code fragment:
Code:
<xf:foreach loop="$userConv.Master.recipients" i="$i" value="$recipient" count="$count" if="{$recipient.user_id} != {$userConv.Master.user_id}"><xf:trim>
    <li>{$i}/{$count}<xf:username user="{$recipient}" defaultname="{{ phrase('unknown_member') }}" /></li>
    </xf:trim></xf:foreach>

The output looks like
... 1/ user1, 2/ user2

The code in Template/Compiler/Tag/Foreach.php does parse the count attribute, so it seems like it's supposed to work...
 
Yes, indeed.

Obviously there are alternative ways to get a count but the best one is probably:
Code:
<xf:set var="$count" value="count($userConv.Master.recipients)" />
<xf:foreach loop="$userConv.Master.recipients" value="" ... and so on
 
Nice one, thanks Chris!
For my particular application, I ended up just using the value of $i after the loop finished (I was able to rearrange the code so that that was all I needed).
 
Back
Top Bottom