View Full Version : Loop to smarty

02-20-2010, 12:04 AM

I know Little about Smarty i know how to assign Easy Vairble to Smarty like

echo $image ; to

$smarty->assign('image', $image);

But how i assign Loop .. this Code Below add Image For each 1 , if image equal 1 then add one image if image 2 add two images .. but i do not know how to assign it with smarty.

for($i=1;$i<=$image; $i++){
echo '<img src="/images/star.png" />';

i tried to do it like this

for($i=1;$i<=$image; $i++){
$smarty->assign('image', '<img src="/images/star.png" alt="" />');

but it only prints out one image .. regrads wht $image equals

02-20-2010, 07:20 AM
Solved it ..

$total =2;
$image = '';
for($i=1;$i<=$total; $i++){

$image .= '<img src="'.PATH.'/images/star.png" />';

$smarty->assign('image', $image);

02-20-2010, 12:54 PM
It would make more sense to assign the number of stars to a variable in smarty then use a for loop in smarty

In your php:

$smarty->assign('maxloop', $total);

Then in your template use

{section name=loop start=1 max=$maxloop}
<img src="'.{$smarty.const.PATH}.'/images/star.png" />