Skip Menu |

This queue is for tickets about the Petal CPAN distribution.

Report information
The Basics
Id: 15944
Status: resolved
Priority: 0/
Queue: Petal

People
Owner: Nobody in particular
Requestors: lloy0076 [...] adam.com.au
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 2.17
Fixed in: (no value)



Subject: Documentation and Examples for the tal:repeat construct
Hi There, Although the documentation does eventually become clear with a little bit of looking and more testing/trying out, it would be nice to have an example that looked something like: tal:repeat One way to use tal:repeat is to create an a reference to an array of anonymous hashes. Here is an example: my $array_ref= [ { firstname=>"David", surname=>"Lloyd" }, { firstname=>"Susan", surname=>"Jones" } ]; With this array you can use the tal:repeat structure. Let's say you have this template - this is a snippet so don't forget the proper name space declarations and such: <table> <tr> <th>First Name</th> <th>Last Name</th> </tr> <tr tal:repeat="name names/list_of_names"> <td tal:content="name/firstname">First Name</td> <td tal:content="name/lastname">Last Name</td> </tr> </table> If you processed that template and the method call "list_of_names" returned an array reference as described above, you'd get: <table> <tr> <th>First Name</th> <th>Last Name</th> </tr> <tr> <td>David</td> <td>Lloyd</td> </tr> <tr> <td>Susan</td> <td>Jones</td> </tr> </table> So, in a tal:repeat construct: tal:repeat="tal_variable_name EXPRESSION" tal_variable_name is the name of the variable you use in your tal template to refer to each row of data you are looping through EXPRESSION should return an array reference, where each row is an anonymous hash You can then refer to the members of the anonymous hash like this: "$tal_variable_name/key_from_hash" ... DSL
Date: Sun, 20 Nov 2005 20:58:32 +0000
From: Bruno Postle <bruno [...] postle.net>
To: Guest via RT <bug-Petal [...] rt.cpan.org>
Subject: Re: [cpan #15944] Documentation and Examples for the tal:repeat construct
RT-Send-Cc:
Thanks, I've added the tal:repeat example to Petal::Cookbook -- Bruno