Experienced monks,

i am about to do some web programming in Perl, so I started to learn about Catalyst and MVC. I have some previous experience with HTML::Mason, but Catalyst uses Template::Toolkit as the first option for view components.

Why? Why is it worth to use (and learn) a different language for the template? I ask, I don't argue, because obviously many people dot it and someone even presented TT as a standard tool for web page development at Vienna.pm lightning talks.

So far I found only 3 reasons hardly applicable in our environment:

Am I wrong? Is there any other - sound and general reason to prefer TT from Mason?

But even If HTML::Mason is the appropriate choice for my environment I can go a bit further. Why to use ANY template engine at all? Why don't use ordinary Perl for the view components?

Everytime I tried a template based development (Perl + HTML::Mason and a bit of PHP + Smarty) I ended up with quite a messy template with lots of iterations and conditions intertwined with plain text.

Where is the advantage of mason template:

<table> <tr><th>Title</th><th>Rating</th><th>Author(s)</th></tr> % for $book (@books){ <tr> <td><% $book->title %></td> <td><% $book->rating %></td> <td> <%perl> my @authors = $book->authors; </%perl> (<% scalar @authors %>) <% join(', ', @authors) %> </td> </tr> %} </table>

over Perl code (I use fictional function-to-html interface, I believe there must be plenty of them)?

print html_table( html_tr( html_th('Title'), html_th('Rating'), html_th('Authors'), ( map { my $book = $_; html_tr( html_td( $book->title ), html_td( $book->rating ), html_td( do { my @authors = $book->authors; scalar(@authors) . ' ' . join( ', ', @auth +ors ); } ) ); } @books ) ) );

In reply to The hidden charm of Template::Toolkit (and templates generally) by roman

Title:
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, details, 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, summary, 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.