Guys,
I'm racking my brains here, searching my ass off, but I can't find it. Is there any way in smarty to say something like "on every alternate iteration of a foreach loop, emit this piece of code"? ("alternate" meaning every 2nd, 4th, 6th etc.)
TIA, YL
Smarty: foreach, every 2nd iteration
Re: Smarty: foreach, every 2nd iteration
Code: Select all
{foreach $myVar as $var}
{if $var@iteration is div by 2}
<b>{$var}</b>
{/if}
{$var}
{/foreach}
HTH,
Ian
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
Re: Smarty: foreach, every 2nd iteration
how about...
Code: Select all
{foreach from=$whatever item="whatever" name=myloop}
{if $smarty.foreach.myloop.iteration is even}
=Don=
Re: Smarty: foreach, every 2nd iteration
My hero! (Actually, I need "is odd", but it works.)Don Chambers wrote:how about...
Code: Select all
{foreach from=$whatever item="whatever" name=myloop} {if $smarty.foreach.myloop.iteration is even}
Thanks.
YL
-
- Regular
- Posts: 3652
- Joined: Mon Feb 13, 2006 2:40 am
- Location: Chicago, IL, USA
- Contact:
Re: Smarty: foreach, every 2nd iteration
Happy to help. The Kinetic template uses this odd/even iteration as well.
=Don=
Re: Smarty: foreach, every 2nd iteration
Which ist what timbalu suggested ;)Code: Select all
{if $smarty.foreach.myloop.iteration is even}
Re: Smarty: foreach, every 2nd iteration
That may very well be, but wasn't obvious to my non-coding mind.onli wrote:Which ist what timbalu suggestedCode: Select all
{if $smarty.foreach.myloop.iteration is even}
Fun fact: Didn't need it after all since it was supposed to add extra markup necessary for IE7 only -- client: "IE7? Drop it. Our stats show 70% Firefox and a lot of Safari. We don't care for IE7."
YL