Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Question about iteration is div by in a foreach loop

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
Greatness
Smarty n00b


Joined: 07 May 2014
Posts: 2

PostPosted: Wed May 07, 2014 7:55 am    Post subject: Question about iteration is div by in a foreach loop Reply with quote

Hello everyone, I just signed up here and I'm pretty new to smarty but trying my best to teach myself step by step. I've got a weird problem currently with my foreach loop and I was hoping to get some feedback here.

Well I've got this...

Code:

<ul>
{foreach name=aussen item=module_data from=$product_listing}
<li>item</li>
<li>item</li>
...
{/foreach
</ul>


...and I wanted to to insert a banner after every 6th item (it's a product listing). I've added the following code in my foreach loop...

Code:

{if $smarty.foreach.aussen.iteration is div by 7}
<img>
{/if}


...which almost works BUT... when i look at my source code it first gets added after the 6th item (which is correct), the second time it gets added after the 7th item. does it count the first item that got added in the loop? if yes, how would it be possible to fix that?

I'm sorry for the worse explanation and crappy english but I hope you understand what I'm trying to say Smile
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Thu May 08, 2014 4:03 am    Post subject: Reply with quote

iteration starts at 1, but index starts at 0.

the following should work.

Code:
{if $smarty.foreach.aussen.index is div by 6}
<img>
{/if}
Back to top
View user's profile Send private message
Greatness
Smarty n00b


Joined: 07 May 2014
Posts: 2

PostPosted: Thu May 08, 2014 6:23 am    Post subject: Reply with quote

Hey, thanks for the swift response. I've tested it a few minutes ago and it works perfectly. Thanks a lot! Smile
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP