Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Dynamically altering static TT templates

by jerrygarciuh (Curate)
on Apr 05, 2002 at 04:54 UTC ( #156823=note: print w/replies, xml ) Need Help??


in reply to Dynamically altering static TT templates

Ovid,
Why TT over the more popular HTML::Template? I am curious because I have recently waded into the latter and want to use my learning time to my best advantage. What recommends TT to you?
TIA
jg
_____________________________________________________
Think a race on a horse on a ball with a fish! TG

Replies are listed 'Best First'.
Template Toolkit compared to HTML::Template ( Re: Dynamically altering static TT templates)
by ViceRaid (Chaplain) on Apr 05, 2002 at 09:10 UTC

    Hi

    I've worked quite a bit with both, and I think they're both excellent modules. However, they're quite different in style, and I think they're suited for different kinds of work. The main differences I can think of are:

      Template Toolkit HTML::Template
    Template Syntax: More complicated, more "Perlish" control structures (keys, values...), and less immmediately HTML-ish (uses custom [% %] notation for template directives, although this can be changed). Simpler, and more HTML-ish at first sight (uses angle brackets <> and attributes).
    Template Data Can work with hashrefs, objects using dot notation, and can pass the values back and forth as arguments. The final value in a dot sequence (foo.bar.thisone) could actually be a method call, or a hash key. Mainly intended to work with key-value pairs and lists of hashrefs. The VAR values are almost always (something like) hash keys.
    Extensibility Easy to extend through the plugins mechanism, and exposes underlying function calls more obviously I wrote a substantial subclass of HTML::Template once ... it wasn't a nice experience. HTML::Template ties the mechanics of a template (reading it, parsing it, preparing it, replacing values) very closely to the implementation of specific template directives (LOOP, VAR, IF) and so on. The parser is a long regex which is trained to look specifically for the sequences like L-O-O-P V-A-R etc, so if you want to add a new tag, you have to rewrite the parser.

    As I say, it's not a criticism of either. One of my clients uses an implementation of HTML::Template extensively. They edit the templates through the browser, the templates are stored in Oracle, and they love it, because all their (cheap) capable HTML-ers find it a doddle to work with. However, the pain factor, for me, of customising HTML::Template was pretty high.

    Template Toolkit's syntax is a bit more scary for people used to vanilla HTML, and the overall flavour of using it is a lot more Perl-ish. But as it exposes more mechanics, it's much easier to customise it to interact with all kinds of different objects that might be relevant to your web application. This might make it a better choice for larger projects.

    Horses for courses, I guess

    //=\\
      Thank you so much for that comparison! Really helpful.
      jg
      _____________________________________________________
      Think a race on a horse on a ball with a fish! TG
Templating Systems (Re: Re: Dynamically altering static TT templates)
by projekt21 (Friar) on Apr 05, 2002 at 09:41 UTC
      Wow, great link! There are enough threads on templating packages I should write a consolidated template resource reference node!
      Thanks!
      jg
      _____________________________________________________
      Think a race on a horse on a ball with a fish! TG
(Ovid) Re(2): Dynamically altering static TT templates
by Ovid (Cardinal) on Apr 05, 2002 at 14:58 UTC

    When I first had to choose a templating scheme for our company, I investigated several options. HTML::Template and Template Toolkit were the two most likely candidates. Even though HTML::Template could have satisfied our needs at the time, I was concerned that, with some of the projects we were planning, that it might become a bottleneck. On the other hand, if we took the trouble to learn Template Toolkit up front, we would have a vastly more powerful templating system available, albeit with potential that we were not tapping.

    flash forward almost two years

    Many people use templates by creating a program, assembling the data, then calling the template and passing it the data. For my current project, I need to create documents out of multiple templates all tied together, some with dynamic content from a variety of different sources. As a result, I am inverting the process and having templates call programs (plugins). This allows me a much richer templating environment. I don't think I could have done that very easily with HTML::Template.

    If your documents are not likely to be terribly complicated, HTML::Template is a fine tool.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      Thanks Ovid! This thread has been most helpful!
      jg
      _____________________________________________________
      Think a race on a horse on a ball with a fish! TG
Re: Re: Dynamically altering static TT templates
by extremely (Priest) on Apr 08, 2002 at 15:55 UTC
    You might also look at Apache mod-perl's template roundup. It does a good job of non-denominationally comparing the template systems.

    --
    $you = new YOU;
    honk() if $you->love(perl)

      Thank you, that was an extremely good link!
      jg
      _____________________________________________________
      Think a race on a horse on a ball with a fish! TG

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2021-10-22 13:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (85 votes). Check out past polls.

    Notices?