Execute code in a loop on two one a foreach

  • Thread starter Deleted member 10469
  • Start date

Deleted member 10469

Hello, how execute code once every two in a foreach please ?

<xen:foreach loop="$renderedChildren" value="$child">
    {xen:raw $child}
    // Here, execute code once every two (eg: 2, 4, 6, 8, 10, 12, etc.)

And how test a variable inside a template please (ex: var_dump or echo) ?
Thanks :)
The foreach has an extra parameter allowing you to specify a count, you need to use that and create an if statement.
The exact code for what you're trying to do is:
<xen:foreach loop="$renderedChildren" value="$child" i="$i">
	{xen:raw $child}
	<xen:if is="$i %2 == 0">
		// Here, execute when iteration count is EVEN.
	<xen:else />
		// Optional. Here, execute when iteration count is ODD.
Hi Zephyr, the solution Chris submitted is the right one (N.B.: even=pair, odd=impair ;) ).
In Chris' example, you can see how to test a variable with xen:if tags.

If you want to dump a variable or a whole template param, XenForo has a template helper for that :
{xen:helper dump, $thread}
The above code inserted in a template will print the $thread variable into your page.
More info : http://xenforo.com/community/threads/1-0-0-b1-finding-variables-available-to-templates.6071/ (I don't know if this one has an updated version in the Resource Manager, though).
Top Bottom