DBX has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to determine which of these two templating systems to standardize on. We currently use HTML::Template for some of our projects, but I am starting a more complex project and the Template Toolkit seems to be much more powerful, allowing a lot more logic inside the template so CGI's don't have to be updated for minor changes. While HTML::Template is simpler, especially for non-programmers to write templates, it seems that either one involves requiring people to learn some new syntax anyway. We will be using the templating system on both live CGI's (mostly on non-mod_perl systems) and to produce static pages. The two issues in deciding which one to go with are ease of use and speed. I would appreciate hearing comparisons between the two especially in terms of how fast they operate and output pages, as well as any other pros and cons. Thanks!

Replies are listed 'Best First'.
Re: HTML::Template vs. Template Toolkit
by Masem (Monsignor) on May 25, 2001 at 00:40 UTC
    If you are not using mod_perl for the dynamic CGI, Template Toolkit may not be the better of the two, because it's slow to load and parse a page (it actually creates perl code); further calls to the same template are speedy, but until you have those calls made, it takes a while. In a non-mod_perl environment, you have no way to store this nice little cache, as opposed to where you can have a mod_perl global sit and cache all TT2 page requestions. HTML::Template is faster but not as powerful, but I think in your situation, it will work better since it merely just in-place regexing, which will be faster in the long run.


    Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain
Re: HTML::Template vs. Template Toolkit
by DrZaius (Monk) on May 25, 2001 at 01:34 UTC
    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).

      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
      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.
      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.

Re: HTML::Template vs. Template Toolkit
by princepawn (Parson) on May 25, 2001 at 00:57 UTC
    Please see this node for more information.

    Edited 2001-05-24 by Ovid