How can I do loops in templates?

Author Message

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

Adolfo Barragán

Monday 27 January 2003 8:12:47 am

> Try this:
> ...

Thanks you. It's ok.

Regards
Adolfo Barragán

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 30 2025 22:25:58
Script start
Timing: Jan 30 2025 22:25:58
Module start 'layout'
Timing: Jan 30 2025 22:25:58
Module start 'content'
Timing: Jan 30 2025 22:25:59
Module end 'content'
Timing: Jan 30 2025 22:25:59
Script end

Main resources:

Total runtime0.8283 sec
Peak memory usage8,192.0000 KB
Database Queries57

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0047 588.2500151.2266
Module start 'layout' 0.00470.0041 739.4766220.7188
Module start 'content' 0.00880.8187 960.19534,460.7734
Module end 'content' 0.82750.0008 5,420.968811.8281
Script end 0.8282  5,432.7969 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00350.4231160.0002
Check MTime0.00120.1480160.0001
Mysql Total
Database connection0.00060.072910.0006
Mysqli_queries0.727287.7974570.0128
Looping result0.00050.0554550.0000
Template Total0.778694.020.3893
Template load0.00180.213020.0009
Template processing0.776893.791020.3884
Template load and register function0.00170.205210.0017
states
state_id_array0.00080.095210.0008
state_identifier_array0.00120.142820.0006
Override
Cache load0.00170.20241000.0000
Sytem overhead
Fetch class attribute can translate value0.00200.237420.0010
Fetch class attribute name0.00220.260340.0005
XML
Image XML parsing0.00060.077420.0003
class_abstraction
Instantiating content class attribute0.00000.001340.0000
General
dbfile0.00140.1745170.0001
String conversion0.00000.001140.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
3content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
9content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
8content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
1content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 23
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs