in reply to HTML::Template vs. Template Toolkit

I am biased.

Any template langauge that lets you 'code' in the template is bad. Logic goes in the code, not the template.You don't want to be debugging logic in more than one place.

You should always have to update your script when logic changes, even if it is minor. Life is easier for your programmers if the code is a black box for your web guys.

And besides, try telling your web guys they can't use dreamweaver with the templates (HTML::Template can use <!-- TMPL_VAR NAME="foo" --> syntax).

Replies are listed 'Best First'.
Re: Re: HTML::Template vs. Template Toolkit
by Masem (Monsignor) on May 25, 2001 at 01:40 UTC
    Not necessarily. A prime example is printing multiple results from a database lookup stored as an array of hashes into a table. I have found it faster to have the foreach-like loop in the template (this with TT2) as opposed to having the foreach in the perl code, as you avoid the extra overhead of calling the template code for each line of the table. If you think of it as Data, Logic, and Display, the logic is the DB lookup, the data is perl's array of hashes, and the Display is the table; the foreach-looping to generate the table naturally falls into the template solution, as opposed to being done in the data handling (perl) area.

    Mind you, doing anything more complicated that loops or simple if statements slows down the template. Data should be processed as much as possible to near the display, but not to actually display it.


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
Re: Re: HTML::Template vs. Template Toolkit
by DBX (Pilgrim) on May 25, 2001 at 01:51 UTC
    I agree in principle, but there are situations where it's easier to put logic in the template. If, for example, a template is built with several other templates selected at run-time based on input values, it seems like it would be more difficult with HTML::Template than TT2. Allowing some logic in the template frees programmer time to write code while designers can build new templates without requiring cgi modifications.
Re: Re: HTML::Template vs. Template Toolkit
by TheoPetersen (Priest) on May 25, 2001 at 17:16 UTC
    I generally agree, and we use HTML::Template on projects at work in large part because it keeps "web guys" out of programming. But one of those guys has a good knowledge of databases and can turn out a utility script when needed; we're considering the move to Template Toolkit because it would take better advantage of his skills.

    For people who ought not to be mucking about with programming, well, just keep them out of the more complex templates. There's nothing in TT2 that stops you from compartmentalizing things to the appropriate skill level.