Forums / Install & configuration / How can I do loops in templates?
Adolfo Barragán
Friday 24 January 2003 9:39:58 am
I've created a calendar and I've separated logic from presentation, so I receive a multidimensional array. Each item is a week wich is again an array with seven items (one for each day). Each day item is an array with two items: the day number and the object id. I want use this object id for a URI like {concat('content/full', $objectId)|ezurl}.
I try a loop in template but print nothing. Furthermore, I don't know create and manipulate variables and loops in "template language" (documentation please).
I need translate the following php code to "template language".Can help me?
$weeks = $Result['weeks']; print "<table>"; foreach( $weeks as $week ) { print "<tr>"; for ($i = 0; $i < 7; $i++) { $day = $week[$i][0]; $objectId = $week[$i][1]; // the following sentence is mixed php and template code $dayLink = {concat('content/full/', $objectId)|ezurl)}
if ($objectId == false) { print "<td>$day</td>"; } else { print "<td><a href=\"" . &dayLink ">\"$day</a></td>"; } } print "</tr>"; }print "</table>";
Thanks in advance.Adolfo Barragán
Jan Borsodi
Sunday 26 January 2003 2:31:02 am
> I've created a calendar and I've separated logic from > presentation, so I receive a multidimensional array. Each > item is a week wich is again an array with seven items (one > for each day). Each day item is an array with two items: the > day number and the object id. I want use this object id for > a URI like {concat('content/full', $objectId)|ezurl}. > > I try a loop in template but print nothing. Furthermore, I > don't know create and manipulate variables and loops in > "template language" (documentation please). > > I need translate the following php code to "template > language". > Can help me? > > $weeks = $Result['weeks']; > print "<table>"; > foreach( $weeks as $week ) > { > print "<tr>"; > for ($i = 0; $i < 7; $i++) > { > $day = $week[$i][0]; > $objectId = $week[$i][1]; > > // the following sentence is mixed php and template > code > $dayLink = {concat('content/full/', $objectId)|ezurl)} > > if ($objectId == false) > { > print "<td>$day</td>"; > } else { > print "<td><a href=\"" . > &dayLink > ">\"$day</a></td>"; > } > } > print "</tr>"; > } > print "</table>"; > > Thanks in advance.> Adolfo Barragán
Try this: {section name=Week loop=$weeks} <tr> {section name=Day loop=7} {let day=$Week:item[$Week:Day:index][0] objectId=$Week:item[$Week:Day:index][1]} <td> {section show=$Week:Day:objectId} <a href={concat('content/full/', $Week:Day:objectId)|ezurl}>{$Week:Day:day}</a> {section-else} {$Week:Day:day} {/section} </td> {/let} {/section} </tr>{/section}
-- Amos Documentation: http://ez.no/ez_publish/documentation FAQ: http://ez.no/ez_publish/documentation/faq
Monday 27 January 2003 8:12:47 am
> Try this:> ...
Thanks you. It's ok.
RegardsAdolfo Barragán