Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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:

  • It is language (Perl) independent. Which seems of no concern for me, since we develop all of our application in Perl (or PL/SQL :-)).
  • It is safer, since the template developer has no access to naked Perl. It also seems of no concern because the template developer is me or my office mate.
  • Different template languague supports the separation of the view from the model and controller. It seems a bit academic for me now.

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (1)
As of 2024-04-24 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found