[MKDoc-commit] [Petal] pod fixes.

bruno at mkdoc.demon.co.uk bruno at mkdoc.demon.co.uk
Sun Nov 20 20:57:34 GMT 2005


Log Message:
-----------
[Petal] pod fixes. Cookbook contrib (DSL)

Modified Files:
--------------
    Petal:
        Changes
    Petal/lib:
        Petal.pm
    Petal/lib/Petal:
        Cookbook.pod

-------------- next part --------------
Index: Changes
===================================================================
RCS file: /var/spool/cvs/Petal/Changes,v
retrieving revision 1.140
retrieving revision 1.141
diff -LChanges -LChanges -u -r1.140 -r1.141
--- Changes
+++ Changes
@@ -2,6 +2,8 @@
 
 2.18
     - $Petal::CodeGenerator::PI_RE should be applied newline insensitively
+    - pod fixes
+    - Cookbook tal:repeat example (DSL)
 
 2.17 Wed Sep  7 15:30:00 2005
     - test 041 check that   becomes chr(160) not chr(194) (William McKee)
Index: Petal.pm
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal.pm,v
retrieving revision 1.136
retrieving revision 1.137
diff -Llib/Petal.pm -Llib/Petal.pm -u -r1.136 -r1.137
--- lib/Petal.pm
+++ lib/Petal.pm
@@ -1079,7 +1079,7 @@
     >
       <tr 
         class="odd"
-        tal:condition="true: repeat/odd"
+        tal:condition="true: audience/odd"
       >
         <td>
           This a odd row, it comes before the even row.
@@ -1087,7 +1087,7 @@
       </tr>
       <tr 
         class="even"
-        tal:condition="true: repeat/even"
+        tal:condition="true: audience/even"
       >
         <td> 
           This a even row.
Index: Cookbook.pod
===================================================================
RCS file: /var/spool/cvs/Petal/lib/Petal/Cookbook.pod,v
retrieving revision 1.7
retrieving revision 1.8
diff -Llib/Petal/Cookbook.pod -Llib/Petal/Cookbook.pod -u -r1.7 -r1.8
--- lib/Petal/Cookbook.pod
+++ lib/Petal/Cookbook.pod
@@ -97,9 +97,72 @@
   print $html;
 
 
+=head2 Basic loops with tal:repeat
 
-=head1 INTERMEDIATE TIPS
+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, array, scalar or object.
+
+You can then refer to the members of the anonymous hash like this:
 
+   "$tal_variable_name/key_from_hash"
+
+
+=head1 INTERMEDIATE TIPS
 
 =head2 Assigning attributes (submitted by Warren Smith)
 
@@ -161,8 +224,6 @@
 
 See L<Petal::Utils|Petal::Utils> for more information.
 
-
-
 =head1 ADVANCED
 
 


More information about the MKDoc-commit mailing list