Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Thanks for the softball.

Here is your job. I will give you an array of text strings. Without manipulating the data in the perl layer, please provide one template that shows them in a bullet list and another template that shows them in a table with three columns with data oriented in columns with one item per cell. On the column oriented version fill in   wherever there isn't a defined value. Be sure external whitespace is nice and consistent.

For extra credit - make the template decide conditionally that if you have less than n items use the bullet list - otherwise use the table.

For extra extra credit - do this exercise - but do it in a text-only based email that will be sent to a user (ie - no html tags).

----- --------- <ul> [%- FOREACH i IN items %] <li>[% i %]</li> [%- END %] </ul> ----- -------- [%- 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> ------ [% PROCESS ${ items.size > 10 ? "" : "" } %] ------ ------ use Template::Alloy; my $t = Template::Alloy->new; my $data = { items => [1 .. 10], }; $t->process("", $data) || die $t->error; $t->process("", $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>&nbsp;</td> </tr> <tr> <td>4</td> <td>8</td> <td>&nbsp;</td> </tr> </table>

Update To me the code layer would be your perl modules and your cgi script (or your mod_perl application). The example given is simplified and contrived - but represents real life situations.
Update 2 s/specifying/manipulating the data/

my @a=qw(random brilliant braindead); print $a[rand(@a)];

In reply to Re: object-oriented composition of model-view with HTML::Seamstress by Rhandom
in thread RFC - Template::Empty by redhotpenguin

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (6)
    As of 2018-06-23 18:54 GMT
    Find Nodes?
      Voting Booth?
      Should cpanminus be part of the standard Perl release?

      Results (125 votes). Check out past polls.