Forum Moderators: coopster

Message Too Old, No Replies

php and smarty

section loop smarty php

         

jpcppc

1:21 pm on Jul 21, 2011 (gmt 0)

10+ Year Member



Hello, I'm having a problem calling a loop using smarty from php. Here's the code I'm working on:


for($k=1;$k<=$score;$k++){

echo '<div class="enab" id="'.$k.'">&nbsp;</div>';

}


for($i=$rem;$i>=1;$i--){

echo '<div class="dis" id="'.$k.'">&nbsp;</div>';

}

$k++;

$smarty->assign('score',?);
$smarty->assign('score2',?);


I need to make them both loop in smarty, one on top of the other.
so they will make a list like so:

<div class="enab" id="1">&nbsp;</div>
<div class="enab" id="2">&nbsp;</div>
<div class="enab" id="3">&nbsp;</div>
<div class="dis" id="4">&nbsp;</div>
<div class="dis" id="5">&nbsp;</div>


using something like (in template tpl):

{section name=score loop=$score}
{$score[score]}
<br />
{/section}

I cannot seem to get it to loop the php 'for' query. Can Anyone shed any light on this?

Thank You.

jpcppc

2:10 pm on Jul 21, 2011 (gmt 0)

10+ Year Member



I could assign:

$smarty->assign('score',$score);
$smarty->assign('rem',$rem);

but how can I loop them?

or...

How can I make:

for($i=$rem;$i>=1;$i--){
$b .= '<div>blah blah blah</div>';
}

an array?

jpcppc

9:05 pm on Jul 21, 2011 (gmt 0)

10+ Year Member



ok, I have decided to just kill it with fire.

bkeep

2:40 pm on Jul 23, 2011 (gmt 0)

10+ Year Member



Do your work in php and pass an array to the Smarty tpl.

{foreach item="item" from=$item_array}
<div id="{$item.count"}">{$item.item}</div>
{/foreach}