This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Install & configuration » How can I do loops in templates?
expandshrink

How can I do loops in templates?

How can I do loops in templates?

Friday 24 January 2003 6:39:58 pm - 2 replies

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

Sunday 26 January 2003 11: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[$Weekbig-smile.gif Emoticonay:index][0]
objectId=$Week:item[$Weekbig-smile.gif Emoticonay:index][1]}
<td>
{section show=$Weekbig-smile.gif Emoticonayomg.gif EmoticonbjectId}
<a href={concat('content/full/', $Weekbig-smile.gif Emoticonayomg.gif EmoticonbjectId)|ezurl}>{$Weekbig-smile.gif Emoticonay:day}</a>
{section-else}
{$Weekbig-smile.gif Emoticonay:day}
{/section}
</td>
{/let}
{/section}
</tr>
{/section}

Monday 27 January 2003 5:12:47 pm

> Try this:
> ...

Thanks you. It's ok.

Regards
Adolfo Barragán

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from