Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 14th, 2012  |  syntax: None  |  size: 0.86 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How to easily create tables in the template toolkit View in perl/Catalyst
  2. sub some_action : Local Args(0) {
  3.     my ( $self, $c ) = @_;
  4.     my $rs = $c->model("SomeTable")->search({},{rows => 10});
  5.     $c->stash( some_rs => $rs );
  6. }
  7.        
  8. [% records = some_rs.all %]
  9. [% RETURN UNLESS records.size %]
  10. [% columns = records.0.columns %]
  11. <table>
  12.   <tr>
  13.   [% FOR column IN columns %]
  14.     <th>[% column | ucfirst | html %]</th>
  15.   [% END %]
  16.   </tr>
  17.  
  18.   [% FOR item IN records %]
  19.   <tr>
  20.     [% FOR column IN columns %]
  21.       <td>[% item.${column} | html %]</td>
  22.     [% END %]
  23.   </tr>
  24.   [% END %]
  25. </table>
  26.        
  27. <table class="ixTable">
  28.     [% FOREACH listing = listings %]
  29.     <tr class="ixRow">
  30.       <td class="ixAddress">[% listing.address %]</a></td>
  31.       <td class="ixPrice">[% listing.listprice %]</td>
  32.       <td class="ixSqFt">[% listing.sqft %]</td>
  33.     </tr>
  34.     [% END %]
  35.   </table>