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

Loop content and assign on every iteration

 
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 -> Plugins
View previous topic :: View next topic  
Author Message
billmn
Smarty n00b


Joined: 28 Dec 2010
Posts: 2
Location: Mantova, Italy

PostPosted: Tue Dec 28, 2010 11:14 am    Post subject: Loop content and assign on every iteration Reply with quote

Hi!
I would make something like this :

Code:
{products order="asc"}
   <div>{$product.title}</div>
   <div>{$product.description}</div>
{/products}


If I have 5 products in database I would repeat the block content 5 times and assign product informations to $product variable on every iteration, for example :

Code:
<div>Product 1</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>

<div>Product 2</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>

<div>Product 3</div>
<div>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</div>



I read this topic ( http://www.smarty.net/forums/viewtopic.php?t=4798 ) but I don't understand how to repeat block content and assign values on every iterations.

Can you help me? Very Happy
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Dec 28, 2010 2:35 pm    Post subject: Reply with quote

see the database example:

http://www.smarty.net/docs/en/language.function.foreach.tpl
Back to top
View user's profile Send private message Visit poster's website
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 -> Plugins 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