Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: The hidden charm of Template::Toolkit (and templates generally)

by roman (Monk)
on Jan 08, 2008 at 13:12 UTC ( [id://661077]=note: print w/replies, xml ) Need Help??


in reply to The hidden charm of Template::Toolkit (and templates generally)

Dear monks,

thanks for your insightful comments.

I will "go with the crowd" as sundialsvc4 in Re: The hidden charm of Template::Toolkit (and templates generally) suggested, with the (probably less populous) mason crowd.

Although I think modules are equivalent to mason components, the mason componenents use different (lowercased) names and path tree which distinguish them better from Controller and Model components, than some MyApp::View::Books, ... view perl modules. Also Mason is already used in my company.

I don't want to bother you with repeating myself, the following lines are meant mostly for my relief.

Personally I consider templates being "false mistresses". They are seducing you with: "Don't code, let's go templating", but soon after start you will meet variables, loops, conditions, methods, ...

The example below is taken from Catalyst tutorial, it is pretty simple and yet it contains a bit of programming, while the authors are not even linked.

[% FOREACH book IN books -%] <tr> <td>[% book.title %]</td> <td>[% book.rating %]</td> <td> [% tt_authors = [ ]; tt_authors.push(author.last_name) FOREACH author = book.a +uthors %] [% # Now use a TT 'virtual method' to display the author cou +nt in parens -%] ([% tt_authors.size %]) [% # Use another TT vmethod to join & print the names & comm +a separators -%] [% tt_authors.join(', ') %] </td> </tr> [% END -%]

In Mason, you start with plain HTML interspersed with occasional perl lines and end up with components, subcomponents, filtering, attributes, methods, ...

However If the only risk of inappropriate tool for view implementation are difficulties caused by my cubicle being tsunamized (Re: The hidden charm of Template::Toolkit (and templates generally)) I stay calm. In Czech republic, I can take the risk. :-)

  • Comment on Re: The hidden charm of Template::Toolkit (and templates generally)
  • Download Code

Replies are listed 'Best First'.
Re^2: The hidden charm of Template::Toolkit (and templates generally)
by Anonymous Monk on Jan 08, 2008 at 17:41 UTC

    In my experience, one killer reason for using Template::Toolkit is Jemplate (also on CPAN).

    With this, you can use exactly the same templates server-side as client-side, and this provides a convenient way of achieving dynamic effects without writing them twice.

    I like the option of building static copies of the site with ttree and tpage, which is useful for high traffic sites that just refresh content every N minutes instead of dealing with a Perl interpreter for each connection. Of course, you can do this with plain Perl, but I find Template::Toolkit just a bit easier.

    p.s. Your example seems a little overcomplicated, wouldn't this do the job instead?

    <td>[% book.authors.join(', ') %] ([% book.authors.size %])</td>

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://661077]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-24 04:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found