in reply to object-oriented composition of model-view with HTML::Seamstress
in thread RFC - Template::Empty
----- bullet.tt --------- <ul> [%- FOREACH i IN items %] <li>[% i %]</li> [%- END %] </ul> ----- columns.tt -------- [%- cols = 3; rows = items.size div cols; rows = rows+1 IF items.size % cols %] [%- FOR i IN [0 .. rows - 1] %] <tr> [%- FOR j IN [0 .. cols -1] %] <td>[% items.${ i + rows * j } %]</td> [%- END %] </tr> [%- END %] </table> ------ optional.tt [% PROCESS ${ items.size > 10 ? "columns.tt" : "bullet.tt" } %] ------ my_perl.pl ------ use Template::Alloy; my $t = Template::Alloy->new; my $data = { items => [1 .. 10], }; $t->process("bullet.tt", $data) || die $t->error; $t->process("columns.tt", $data) || die $t->error; __END__ prints <ul> <li>1</li> <li>2</li> <li>3</li> <li>4</li> <li>5</li> <li>6</li> <li>7</li> <li>8</li> <li>9</li> <li>10</li> </ul> <table> <tr> <td>1</td> <td>5</td> <td>9</td> </tr> <tr> <td>2</td> <td>6</td> <td>10</td> </tr> <tr> <td>3</td> <td>7</td> <td> </td> </tr> <tr> <td>4</td> <td>8</td> <td> </td> </tr> </table>
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: object-oriented composition of model-view with HTML::Seamstress
by metaperl (Curate) on Feb 25, 2008 at 19:57 UTC | |
by Rhandom (Curate) on Feb 25, 2008 at 21:37 UTC | |
|
Re^2: object-oriented composition of model-view with HTML::Seamstress
by metaperl (Curate) on Feb 25, 2008 at 20:08 UTC |