Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Advice Choosing a Templating System

by ghettofinger (Monk)
on Mar 01, 2005 at 23:24 UTC ( #435648=perlquestion: print w/replies, xml ) Need Help??

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

Wise and knowing monks,

I am really just starting to figure out what makes a good web page, and some things that save an incredible amount of time when making a site, such as templating systems. I guess I should say that I know enough to know that I need one. I have been using server side includes for headers and footers but I think that I am ready to take this to the next level by using a specialized templating system.

I have looked around and I found the article Choosing a Templating System which is pretty hot, but I thought I might ask a couple of questions.

Do any of you think that one templating system makes more sense or is easier to comprehend? Maybe it just comes down to how well it is documented. Also I am looking for session management. Do any of these frameworks incorperate this kind of functionality?

I appreciate any links, book titles or words of advice you may have.

Many thanks to all,

Replies are listed 'Best First'.
Re: Advice Choosing a Templating System
by sh1tn (Priest) on Mar 01, 2005 at 23:58 UTC
      That link is awesome. Thank you.
Re: Advice Choosing a Templating System
by baztastic (Scribe) on Mar 02, 2005 at 02:29 UTC

    Personally I like the Template Toolkit. It is written in Perl and fairly easy to pick up.

    As for comparing it to others this is all I can do: On one hand I have never tried any other templating system so I can't say how the TT stacks up to them. On the other I have never tried any other templating system because the TT works fine for me.

    It doesn't have any direct session management but if you are using Apache there is the Template::PLugin::Apache::SessionManager module for that.

      I think that this is the route I am going to take. I am currently reading the Perl Template Toolkit By Darren Chamberlain, David Cross and Andy Wardley. It looks very cool. I am looking at the Template::Plugin::Apache::SessionManager too. My question about this is can this be used for session management for logged in users, etc? I am going to keep reading and start a search on google but I was wondering how you (or anyone else) was taking care of authentication with TT.
Re: Advice Choosing a Templating System
by cowboy (Friar) on Mar 02, 2005 at 00:09 UTC
    I've used Mason on a couple of fairly large projects, and love it.
    It's fairly quick to get up to speed on, uses perl, with a few special html-ish tags, includes a caching api built on Cache::Cache, and has quite a number of modules that extend the core system. (such as adding Apache::Session support)

    I don't know enough about other systems, at least not any recent usage, but in my mind, the fact I don't have to learn a fancy mini-language for my templates, and just write them in perl, is a big plus.

    Too many templating systems seem to have been written by people wanting to design a programming language, rather than a templating system.
      Mason is great if the only people who will ever hack your templates are already Perl programmers.

      However, the mini-language of Template Toolkit is soooo much easier to teach to non-programmers who might be hacking the HTML of your site. So says my clients that are using TT in their web apps.

      So, while you might prefer the Mason approach, there are many reasons to prefer the "mini-language" approach.

      -- Randal L. Schwartz, Perl hacker
      Be sure to read my standard disclaimer if this is a reply.

        Each templating system / text pre-processor, or whatever is intended for a particular audience. You have to analyze what functionality you're going to need, and who is going to be using it.

        If you can take care of 99% of your site with a CMS system that requires no technical, and leave the last 1% to someone with some programming skills, it's probably better than giving them something they can accidentally break.

        For instance, back in my undergrad days, the group I worked for did a web page that called an SSI for the bulk of its content. Unfortunately, the site's 'owner' kept editing the page in a WYSIWIG editor which pulled down its content through HTTP ... I tried leaving a hint, but as they never looked at the source, they never found my not-so-subtle hint.

        My advise, if you're going to be the only one using it, is to take a look at the syntax, and see if it makes sense to you. If it does, then you're probably fine -- but if the maintainer has a different mindset than you do, you might want to look at something else.

        If whoever is developing content has absolutely no programming skills at all, and you're not dealing with database backends and the like, you might also take a look at Markdown.

        True. Although in my (limited) experience, I've found that generally, teaching the people who do design anything to do with languages, mini, or not, seems to be a crap shoot. Either they can grasp the concept, or they can't.

        If they can, mason, or template toolkit, or any other comes easy enough. They can include a header/footer, call another block of code in a loop, without having to be 'programmers', after a simple example or two.

        If they cannot, it doesn't seem to matter if the template is as simple as:
        they can't seem to understand that we'll put the proper value there.
Re: Advice Choosing a Templating System
by punkish (Priest) on Mar 02, 2005 at 04:16 UTC
    No collection of biased suggestions about which templating system to use will be complete without making a plug for HTML::Template. I have yet to find a program more complete and simple at the same time. Does its thing, does it fast, and does it with least amount of frills.

    Stick to doing all your programming logic in Perl, and even if you are the only one doing the html, do it separately using H::T tags.

    If you don't believe me, ask someone else.

    when small people start casting long shadows, it is time to go to bed
Re: Advice Choosing a Templating System
by CountZero (Bishop) on Mar 02, 2005 at 06:54 UTC
    If you are afraid that the content/layout people might mess up with a "difficult" templating language, you could have a look at Template::Magic and its friends.

    For not too difficult pages, it works a lot like SSI and can even handle loops, etc. in a straight-forward way without having to jump through too many hoops or including very un-HTML-like tags.


    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

        Care to elaborate?

        Is his code bad, or do you just dislike the author and think the rest of us should too?

Re: Advice Choosing a Templating System
by exussum0 (Vicar) on Mar 02, 2005 at 13:42 UTC
    My advice is, pick one that suits the competencies of all people using it and fits your standards. If you have sloppy programmers, use a template system that has no ability to go beyond substitution of variables and a few loop constructs. If you have smart guys who are diligent, you may want to use something that can be used powerfully. I'm a pestimist, so I believe everyone is stupid, including me, and go for the least powerful template system. Logic in presentation layer beyond simple constructs can be quite messy. Extensibility is another thing.

    Give me strength for today.. I will not talk it away..
    Just for a moment.. It will burn through the clouds.. and shine down on me.

Re: Advice Choosing a Templating System
by jbrugger (Parson) on Mar 02, 2005 at 09:17 UTC
    I'd have a look at HTML::Template::Expr or Petal (the Plone template system). Especially the last (petal) makes it possible for html-guru's to write html without having to concern about Perl. I prefer HTML::Temlate::Expr over HTML::Template, becouse you can use simple expressions (though that should be avoided :-) ).
Re: Advice Choosing a Templating System
by InfiniteLoop (Hermit) on Mar 02, 2005 at 04:55 UTC
    I have used HTML::Template (with CGI::Application, which is a very good combination.). I had earlier used Mason, briefly. I found HTML::Template to be more simpler and easy to use.
      I'm also an advocate of HTML::Template. I find it follows the MVC philsophy very well, ensuring content is kept separate from code as much as possible. That translates to faster application deployment and easier maintenance.

      Combined with CGI::Application, they also work well in mod_perl environments.

      I agree. I've just wrapped up a little project that would have taken a dog's age doing it in my "old way". It ended up taking a mere two days, including learning HTML::Template, CGI::Application, and Perl IPC. And it's much more maintainable... :-)
Re: Advice Choosing a Templating System
by jdtoronto (Prior) on Mar 02, 2005 at 18:58 UTC
    Hi ghettofinger,

    Have you realized that you touched one of the religious touch-stones of this community? The choice of a templating system and an application framework has more to do, in many respsects, with good luck rather than good management.

    For my own purposes I was using things like FormBuilder and Data::FormValidator to help be get past the 'all hand crafted' stage. I still have one legacy application I support which is now over 60,000 lines of Perl and all of the HTML is done with HEREDOC print statements. Oh boy, is that a beast to maintain. Much of it uses no external modules at all and for some of it is used. THe beginnings of the code must now be over 10 yearrs old - I started it in Perl 4 but it first saw the light of day as my first P5 application. Oh, did I say it does not use strict for which I regularly castigate myself now!

    Nowadays my preference is CGI::Application and its related family of modules ( BEWARE - the CGI::Application::Plus family of modules are from DOMIZIO and should be avoided as suggested earlier by merlyn ). It has closely coupled support for Data::FormValidator and uses HTML::Template as its default templating system. HTML::Template might not be the most exoctic of templating systems - it has nothing like the 'oh it was once a mini-language' extensions of Template::Toolkit but is far faster to learn, far easier to teach to HTML coder types and when coupled with Cascading Style sheets has allowed me to produce some huge, highly adaptable, but very easilly maintained intranet applications.

    Your mileage may vary, and almost inevitably will. But this environment has been very good to me, is well supported by a group of higly professional coders and has its own website and mailing list.


      I knew that there would be many opinions here and that is why I asked. I was hoping for many opinions, really. I like all of the advice that is given here. I have never seen a community with such well informed and eloquent members.

      I also know that once I start with one method I will be very likely to stick with it. I am really starting to ramp up some sites and I want to have them all coded with the same method to ease the administrative burden. I am super glad I asked this question and even more pleased with the response.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://435648]
Approved by injunjoel
Front-paged by Tanktalus
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2019-10-15 01:04 GMT
Find Nodes?
    Voting Booth?