Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Survey of Surveys on HTML Templating systems

by tphyahoo (Vicar)
on Feb 23, 2005 at 15:59 UTC ( [id://433729]=perlmeditation: print w/replies, xml ) Need Help??

Survey of Surveys on HTML Templating systems / Web Frameworks (Sorting out the Technology Soup)

UPDATE: I either missed Catalyst, or Catalyst wasn't out yet, when I first posted this. At this point in time, I am devoting most of my "web framework learning" energy to learning this framework. Run and check it out!

I need to choose an html templating system that plays well with Dreamweaver for the design aspects, and an open source db (mysql or postgres) for the back end.

Ideal would be a mock application (or open source real application) written with Mason or Embperl (my top choices) including a framework for managing the db, that's all ready to go, and I can just start tinkering with it to suit my purposes, rather than start something from scratch. But I wasn't able to find anything like that.

Anyway, after spending some time doing research mainly with perlmonks and google, I thought it would be helpful to others in my situation to present a survey of my findings. There is a LOT written about this, without a clear "winner" in the competing technology soup. (Though as stated above, I'm beginning to lean towards Mason/Embperl.)

UPDATE: There's a mason demo at Perl Apprenticeship Site. Unfortunately I don't think this is db enabled, but I could be wrong about that -- need to check into this more carefully. This is the "official" sample site described in the masonbook. More promisingly, there a number of mason powered apps at mastonhq.com. Bricolage uses postgres, I may be looking at that first.

A not very satisfying demo of embperl is at Talk on Apache, mod_perl, and embperl

Also, Metaperl (aka princepawn) was kind enough to provide me with a demo app of his Seamstress framework. There is no link to do this from his web page, but ask nicely and hopefully you will be in luck.

Metaperl also referred me to the "bivio" framework, which also has a demo "petshop" webshop, nicely tar.gzed. (See discussion below). However, in The Bivio Model and Algorithm for Authorization (slides available), Metaperl notes that even after intensive study bivio strained his powers of understanding... which I find kind of scary. So, I may choose to study bivio as an example of a really cool framework, but do my real work in Mason (or possibly Seamstress).


Overview

Of hisorical interest may be jonas liljegren's rant (undated, my guess is 1999 or before)
  • Back in the day, he was "Frustrated about all these template models!"
  • Of major modern templating systems, mentions only HTML::Template.
  • The more things change, the more they stay the same.

A more current major article on the topic is perrin's Choosing a templating system also at perl.com here. (Last major change Jun 5 2002, originally written Sep 21 2001. I gave both urls since the article appears to be updated occasionally, so maybe one is more current than the other.)

  • A long article that attempts to compare all major modern perl templating systems.
  • At the end it's findings are summarized as:

Application Framework
Pipeline or Callback
Parsing Method
Language
HTML::Mason Framework Callback Compiled Perl
Template Toolkit Just Templates Pipeline Compiled Mini-Language
Apache::ASP Framework Callback Compiled Perl and XSL
HTML::Embperl Framework Callback Compiled Perl
SSI Just Templates Callback Repeated Parse Mini-Language
AxKit Framework Pipeline Compiled or Cached Parse Tree Perl and XSL and Mini-Language(s)
HTML::Template Just Templates Pipeline Cached Parse Tree Mini-Language
Text::Template Just Templates Pipeline Compiled Perl

This led me to conclude I probably want to use either Mason or Embperl, as these are the two top contenders for frameworks.

Pertinent to perl newbies for getting started on web apps is How to calculate development time?. Newbie (at the time) Siddharta asks, and gets, advice for building a web application from scratch. This is mainly about estimating project time, but there is also a lot of advice on which framework to use. Good thread.

And, some Perlmonks threads that discuss the pros and cons of various templating systems without a clear consensus preference for a particular one.

What is the best tool to embed perl in HTML? (Q&A, August 2, 2000) / Best templating system? (Jun 30 2000)

  • Mason, Embperl, and Template are recommended by various monks.
  • It's stated that Embperl plays well with Dreamweaver
  • Refining the CGI process through structure and templates (Apr 16, 2001, Boo Radley)
    • Started by Boo Radley, attempting to roll his own Web/CGI framework
    • Recommended by princepawn on his home node.
    • Corion plugs HTML::FormValidator and others agree

    OO CGI Engine (Jan 2 2002)

    • Discussion of OpenInteract, CGI::Application, and HTML::Template, with positive things to say about all these.
    • dnmiller2k mentions that CGI::Application uses HTML::Template, but Swiftone counters that this is just for installation, and you can use it with Template-Toolkit if you want.
    Update: No demo for "open interact", at least none that I could find. But supposedly it's coming soon.

    Another perrin article that's worth a read is Building a Large-scale E-commerce Site with Apache and mod_perl, which recounts his adventures at now-defunct etoys.


    Princepawn/Metaperl/Merlyn Stuff


    Dreamweaver and Perl

    Jeffa wrote HTML::Template extensions for dreamweaver which enables you to "se HTML::Template tags in Dreamweaver just like they would any other object - by clicking on an icon which places the resulting HTML code in the document."

    But it's no longer being maintained.

    Two perlmonks threads about this.

    • Dreamweaver/Perl integration tools (Dec 8 2001)
      • User wants help integrating Dreamweaver Templates (a Dreamweaver feature not to be confused with perl templating) and perl (doesn't specify which perl web framework)
      • Adviced that Jeffa put together a tool that helps you manage perl from within Dreamweaver, using Dreamweaver's "Dreamweaver Template" feature
      • Tphyahoo (me) mentions MasonAndDreamweaver at the MasonHQ wiki. This seems to indicate that Mason and Dreamweaver play together okay.
    • HTML::Template and Dreamweaver MX (Nov 21 2003)
      • Newbie asks for help with Dreamweaver and HTML::Template (not specifying he wants help with Dreamweaver Templates)
      • Newbie is advised to have a look at Jeffa's tool for integration with Dreamweaver Templates (I think this advice was confused).
      • Jeffa states that he hasn't been maintaining this since 2001, and it's now out of date since there have been a lot of changes with Dreamweaver MX. "Dreamweaver is a "funky beast" says Jeffa.
      • Tphyahoo (me) mentions that Dreamweaver Templates are a special Dreamweaver feature, which aren't used on every project, and suggests Mason, linking back to the 2001 article.
    Also found CGI.pm - Dreamweaver or somesuch? (April 2001)
    • Newbie asks for help integrating perl and dreamweaver
    • Monks express general disdain for Dreamwever
    Conclusion: Dreamwever Templates and perl, maybe not such a good idea. However, Dreamwever and Mason, maybe not such a bad idea. Also What is the best tool to embed perl in HTML? stated that Embperl and Dreamweaver is ok.

    Descriptions/Tutorials on particular frameworks

    HTML::Mason module review (Feb 1 2001)
    • Overall positive review of this (at the time) new framework
    Perl.com article Using CGI Application (June 5 2001)

    I'm sure there's a lot more, so if I get comments I will try to update as appropriate.

    Other stuff

    proposal for HTML::FormValidator upgrade

    • likes html::formvalidator, but mentions some things that could be done better.
    • At end mentions that many of his concerns are addressed by data::formvalidator

    Edit by tye: Remove P tags inside TABLE

    Replies are listed 'Best First'.
    Re: Survey of Surveys on HTML Templating systems
    by dimar (Curate) on Feb 23, 2005 at 16:16 UTC

      Excellent.

      Templating systems are very similar to text editors / IDEs. Almost everyone has one, and everyone has reasons why their own personal favorite is "the best". This inclination also tends to bias people against trying other systems when they already know how to use one that suits their purposes and preferences. The result is myopic entrenchment.

      Consequently, an unbiased observer is not very likely to find a legitimate side-by-side comparison without a lot of hard work and fortitude not to be swayed by people's (sometimes ill-informed) opinions.

      Good job, *definitely* update this as appropriate. This kind of 'neutral' evaluation is a definite (++).

      Now, if you could do a similar analysis for text editors and IDEs and have a report up by tomorrow morning, that'd be great mm'kay? ;-)

    Re: Survey of Surveys on HTML Templating systems
    by fergal (Chaplain) on Feb 23, 2005 at 20:06 UTC
      None of the surveys I've seen look at Petal which is based on Zope's TAL/ZPT. As far as I'm concerned there is no other way to do HTML/XML templates.

      Example:

      Welcome back <b tal:content="user/name">Sample Username</b>, you last logged in <i tal:content="user/last_login">Sat 23rd Aug</i>

      When you look at this in dreamweaver or a browser you'll see

      Welcome back Sample Username, you last logged in Sat 23rd Aug

      (view source on this page and you'll see that I have simply pasted in the code)

      When you run this through the Petal engine you pass in a hash of data, say $h. Assuming

      $h = { user => { name => "Fergal Daly" last_login => "Feb 22nd" } }
      The processed output will be

      Welcome back Fergal Daly, you last logged in Feb 22nd

      As you can see, the HTML beforehand is well formed, includes sample values for the dynamic parts and all you have to do with Dream weaver is apply styles to the sample data and all will be well. At template compile time, all the sample data is discarded and then at run time, the real data is inserted.

      Of course TAL handles loops and conditionals etc. The thing that takes the most getting used to is that it's a little verbose. Unfortunately this is a necessary side effect of being truly compatible with XML/HTML.

        Everything you said about Petal applies to Seamstress. However, the advantage of Seamstress is that you don't need to learn a mini-language.

        So let's take the same content:

        Welcome back <b tal:content="user/name">Sample Username</b>, you last logged in <i tal:content="user/last_login">Sat 23rd Aug</i>
        And when you look at this in dreamweaver or a browser you'll see
        Welcome back Sample Username, you last logged in Sat 23rd Aug

        And assuming

        $h = { user => { name => "Fergal Daly" last_login => "Feb 22nd" } }

        The processed output will be

        Welcome back Fergal Daly, you last logged in Feb 22nd

        Now for the big difference

        Of course TAL handles loops and conditionals etc.
        Seamstress does not. Perl has loops and conditionals and sees no need for their re-invention.
        The thing that takes the most getting used to is that it's a little verbose. Unfortunately this is a necessary side effect of being truly compatible with XML/HTML.
        I agree with you here, but I personally could have it no other way either. Here is how seamstress would template the same thing:
        require html::welcome_form; my $tree = html::welcome_form->new; my $user_name = $tree->look_down('tal:content' => 'user/name'); $user_name->replace_content($hash->{user}{name}); my $last_login = $tree->look_down('tal:content' => 'user/last_login); $last_login->replace_content($hash->{user}{last_login});

        or with a loop

        for my $content (qw(name last_login)) { $tree->look_down('tal:content' => $content) ->replace_content($hash->{user}{$content}); }
          I don't get it, from the example you gave, seamstress requires a whole load of extra Perl code as well as a HTML template.

          As for a mini-language it's almost non-existent. Petal's loops are very simple

          <table> <tr tal:repeat="thing user/things"> <td tal:content="thing/name">Widgets </td>: <td tal:content="thing/count">10</td> </tr> </table>
          this will produce one row for every element of $h->{user}->{things}.

          That's as complex as you can get with loops. You just supply an array and Petal loops over it. This forces you to prepare all your data in advance and then just pump it into the template (although you can call methods as well as doing hash lookups so it's possible to lazily produce the data only as it's needed).

        I'm in the process of updating my article, and it will include Petal. The HTML_Tree module referred to in the current version is a dead project now.
    Re: Survey of Surveys on HTML Templating systems
    by metaperl (Curate) on Feb 23, 2005 at 17:47 UTC
      Princepawn has come up with his own framework, Seamstress, though I'm not sure how serious he is about it
      Thank you for your balanced assessment of templating systems. My first question would be: have you looked at the docs and philosophy behind HTML::Seamstress? Would you agree that Seamstress is a rather unique beast in the jungle HTML templating systems? The only thing similar to it is XML::LibXML, which is based on XHTML and hence requires better structured documents. It also is not based on HTML::Tree which means that you cannot get the magnificent table-building abilities of HTML::ElementExtended

      Now on to your question about my seriousness.

      • Seamstress originally contained HTML templating subroutines and support for preparing HTML documents for templating via a command-line tool. All subroutines for templating have been moved out to a separate tested and documented distribution, HTML::Element::Library. Seamstress is now simply compiler support for a large collection of generic tree manipulation routines, which includes HTML::Element::Library, HTML::ElementExtended and the root class HTML::Element (which is part of HTML::Tree).
      • I recently developed a database-driven website in CGI::Prototype (merlyn'stool), Data::FormValidator, Class::DBI, and HTML::Seamstress. If you click on any page, at the bottom is a "View source" link which gives you an idea of how Seamstress works.

        I can report that I was pleased with my ability to create common look and feel by normal object-oriented programming as opposed to something like a Mason autohandler.

      • I am very happy with my tool and responsive to input on it's improvement. It is not a popular tool. It was well-received at the Thousand Oaks Perl Mongers meeting recently. I meant to give a talk on DFV but they got interested in Seamstress so I explained how it worked and they liked it. That being said, HTML::Template and Template, Mason, Embperl are much more popular and have much longer track records in critical corporate situations. Using Seamstress is a commitment to improving it as you need it - much as I do.

      HTML::Formvalidator

      I think the most popular validation module is Data::FormValidator and I am happy with its performance. You might take a look at that.
        I would say Petal offers the same sort of approach as Seamstress. It's pretty mature and seems to have an active community.
          I would say Petal offers the same sort of approach as Seamstress.
          I thought Petal was the same thing as Seamstress but after joining the GMANE list and reading the docs it is very different.
          • Petal provides a mini-language. Seamstress and XML::LibXML usage is nothing but object-oriented Perl.
          • Petal is xml-based, which is fine if you have well-done XHTML. Seamstress is based around the flexible HTML::TreeBuilder which uses HTML::Parser and can use old skool HTML with no problem.
          • did you see my post about creating alternating table rows with Petal? The way to do that in Seamstress or XML::LibXML is vastly different and in neither of our cases involves a mini-language.
        Hi, thanks for your feedback!

        No, I haven't looked at the docs for Seamstress, just what I find clicking around in perlmonks. I was pretty overwhelmed by the amount of information out there and couldn't follow everything up. Maybe I'll have a closer look now.

        One thing that might move me to try Seamstress is if there was a dummy application with a db back end that I could just take over and mold to my purposes. Is that what I'll get by clicking the view source link as you suggest? Going to check it out...

          Okay the view source thing is cool, but what I really want is the thing downloaded in a tarbell, including db dump, where I can play with it and see if I like it.

          For instance, my first question is, where are the html templates? I guess they're in there somewhere, but how close to html do they look like? Close enough that I can load them in dreamweaver?

          If you just tarballed the whole thing you might get more people playing with it, that's what MS does with ASP.net.

          But from viewing the source I agree it's clean, it's nice, it looks promising.

    Re: Survey of Surveys on HTML Templating systems
    by perrin (Chancellor) on Feb 23, 2005 at 19:06 UTC
      This led me to conclude I probably want to use either Mason or Embperl, as these are the two top contenders for frameworks.

      There are actually many frameworks based on the other templating modules, but I didn't review them because I was trying to limit the scope of that article. There's a partial list here. I also submitted a talk this year about MVC systems like Maypole, OpenInteract2, and Catalyst.

    Dont forget bivio!
    by metaperl (Curate) on Feb 23, 2005 at 22:11 UTC
      If you really want to see a clean MVC system, you must take a look at Bivio and join the mialing list.

      They have an online petshop demo with View source functionality.

        Could you comment on the relative strengths and weaknesses of bivio versus your Seamstress?

        UPDATE: Metaperl has mentioned bivio in The Bivio Model and Algorithm for Authorization (slides available), where he notes that he initially intended to base Seamstress on it. But then he decided not to because even after intensive study bivio strained his powers of understanding.

    Re: Survey of Surveys on HTML Templating systems
    by holli (Abbot) on Feb 24, 2005 at 16:51 UTC
      Just for completeness, i´d like to mention PLP, a creation of our fellow brother Juerd. I´ve never used it, but from what I´ve read it seems to be similar to PHP. From the homepage:
      PLP is yet another Perl embedder, primarily for HTML documents. Unlike with other Perl embedders, there is no need to learn a meta-syntax or object model: one can just use the normal Perl constructs. PLP runs under mod_perl for speeds comparable to those of PHP, but can also be run as a CGI script.


      holli, /regexed monk/
    Re: Survey of Surveys on HTML Templating systems
    by pingo (Hermit) on Feb 24, 2005 at 14:02 UTC
      This may be a bit off-topic, but does anyone know if there is a Velocity template parser for Perl? Velocity seems to be getting more and more popular in the Java world, and the templates doesn't look like they would be too hard to parse. :-)
    Re: Survey of Surveys on HTML Templating systems
    by Anonymous Monk on Feb 01, 2006 at 02:21 UTC
      Nice writeup, overall. One nit:

      Newbie is advised to have a look at Jeffa's tool for integration with Dreamweaver Templates (I think this advice was confused)

      This advice was not confused. jeffa's Dreamweaver extension added support for HTML::Template style markup in Dreamweaver. It had nothing to do with Dreamweaver templates.

    Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Domain Nodelet?
    Node Status?
    node history
    Node Type: perlmeditation [id://433729]
    Approved by kvale
    Front-paged by kutsu
    help
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this?Last hourOther CB clients
    Other Users?
    Others meditating upon the Monastery: (6)
    As of 2024-03-19 02:47 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found