perrin 01/08/23 10:37:55 Modified: features tmpl-cmp.html Log: Updated version, added info on Mason/Embperl OO differences, added URLs. Revision Changes Path 1.2 +45 -26 modperl-site/features/tmpl-cmp.html Index: tmpl-cmp.html =================================================================== RCS file: /home/cvs/modperl-site/features/tmpl-cmp.html,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- tmpl-cmp.html 2001/08/01 03:35:13 1.1 +++ tmpl-cmp.html 2001/08/23 17:37:55 1.2 @@ -3,7 +3,7 @@ <TITLE>Choosing a Templating System</TITLE> </HEAD> -<BODY bgcolor="#ffffff"> +<BODY> <A NAME="__index__"></A> <!-- INDEX BEGIN --> @@ -76,7 +76,8 @@ <P> <H1><A NAME="choosing a templating system">Choosing a Templating System</A></H1> <P>by Perrin Harkins</P> -<P>Version 0.9<P> +<P>version 1.0</P> +<P> <HR> <H1><A NAME="introduction">Introduction</A></H1> <P>Go on, admit it: you've written a templating system. It's okay, @@ -208,7 +209,7 @@ always cranks up the flame on web development mailing lists.</P> <P>Some systems use in-line Perl statements. They may provide some extra semantics, like Embperl's operators for specifying whether the code's -output should be displayed or Mason's <%init> sections for specifying +output should be displayed or Mason's <CODE><%init></CODE> sections for specifying when the code gets run, but at the end of the day your templates are written in Perl.</P> <P>Other systems provide a specialized mini-language instead of (or in @@ -258,16 +259,16 @@ <% } %></PRE> <P>And now Template Toolkit:</P> <PRE> - [% USE product(sku=bar1234) %]</PRE> + [% USE product(sku=bar1234) %] +</PRE> <PRE> + [% IF product.isbn %] It's a book! [% ELSE %] It's NOT a book! - [% END %] -</PRE> + [% END %]</PRE> <PRE> - [% FOREACH item = product.related %] You might also enjoy [% item.name %]. [% END %]</PRE> @@ -427,10 +428,11 @@ flexibility and power before settling on this simple approach.</P> <P> <H2><A NAME="html::mason">HTML::Mason</A></H2> +<P><A HREF="http://www.masonhq.com/">http://www.masonhq.com/</A></P> <P>Mason has been around for a few years now, and has built up a loyal following. It was originally created as a Perl clone of some of the most interesting features from Vignette StoryServer, but has since -become it's own unique animal. It comes from a publishing background, +become its own unique animal. It comes from a publishing background, and includes features oriented towards splitting up pages into re-useable chunks, or ``components.''</P> <P>Mason uses in-line Perl with a compilation approach, but has a feature @@ -451,17 +453,20 @@ from the values passed in the URI query string.</P> <P>While the documentation mostly demonstrates a callback execution model, it is possible to use Mason in a pipeline style. This can be -accomplished in various ways, including designating components as -``autohandlers'' which run before anything else for requests within a -certain directory structure. An autohandler could do some processing -and set up data for a display template which only includes minimal -in-line Perl. There is also support for an object-oriented site -approach, applying concepts like inheritance to the site directory -structure. For example, the component at /store/book/ might inherit a -standard layout from the component at /store/, but override the -background color and navigation bar. Then /store/music/ can do the -same, with a different color. This can be a very powerful paradigm -for developing large sites.</P> +accomplished in various ways, including building special components +called ``autohandlers'' which run before anything else for requests +within a certain directory tree. An autohandler could do some +processing and set up data for a display template which only includes +minimal in-line Perl. There is also support for an object-oriented +site approach, applying concepts like inheritance to the site +directory structure. For example, the autohandler component at +/store/book/ might inherit a standard layout from the autohandler at +/store/, but override the background color and navigation bar. Then +/store/music/ can do the same, with a different color. This can be a +very powerful paradigm for developing large sites. Note that this +inheritance is only supported at the level of methods defined in +autohandler components. You can't override the component +/store/foo.html with another one at /store/book/foo.html.</P> <P>Mason's approach to debugging is to create ``debug files'' which run Mason outside of a web server environment, providing a fake web request and activating the debugger. This can be helpful if you're @@ -481,6 +486,7 @@ helpful user community go a long way.</P> <P> <H2><A NAME="html::embperl">HTML::Embperl</A></H2> +<P><A HREF="http://perl.apache.org/embperl/">http://perl.apache.org/embperl/</A></P> <P>Embperl makes its language choice known up front: embedded perl. It is one of the most popular in-line Perl templating tools and has been around longer than most of the others. It has a solid reputation for @@ -512,9 +518,12 @@ toggled on and off).</P> <P>Embperl includes something called EmbperlObject, which allows you to apply OO concepts to your site hierarchy in a similar way to the -inheritance features mentioned for Mason, above. This is a very -convenient way to code sites with styles that vary by area, and is -worth checking out.</P> +autohandler and inheritance features of Mason, mentioned above. This +is a very convenient way to code sites with styles that vary by area, +and is worth checking out. EmbperlObject includes the ability to do +overrides on a file level. This means that you can have a directory +like /store/music which overrides specific templates and inherits the +rest from a parent directory.</P> <P>One drawback of older versions of Embperl was the necessity to use built-in replacements for most of Perl's control structures like ``if'' and ``foreach'' when they are being wrapped around non-Perl sections. @@ -540,6 +549,7 @@ provides performance improvements.</P> <P> <H2><A NAME="apache::axkit">Apache::AxKit</A></H2> +<P><A HREF="http://axkit.org/">http://axkit.org/</A></P> <P>AxKit is the first mod_perl page generation system to be built from the ground up around XML. Technically, AxKit itself is not a templating tool but rather a framework for stringing together different modules @@ -562,8 +572,8 @@ XPath functions for querying an XML document and manipulating the retrieved data. XPathScript can also be used in a declarative fashion, specifying the formatting of particular elements in the XML -input. For example this snippet will change all <foo> tags in an XML -document to BAR in the output::</P> +input. For example this snippet will change all <CODE><foo></CODE> tags +in an XML document to BAR in the output::</P> <PRE> <% $t->{'foo'}{pre} = 'BAR'; @@ -599,6 +609,7 @@ languages and tools.</P> <P> <H2><A NAME="apache::asp">Apache::ASP</A></H2> +<P><A HREF="http://www.apache-asp.org/">http://www.apache-asp.org/</A></P> <P>Apache::ASP started out as a port of Microsoft's Active Server Pages technology, and its basic design still follows that model. It uses in-line Perl with a compilation approach, and provides a set of simple @@ -639,10 +650,12 @@ author, has reported much better results from Samba file-sharing than from NFS.) This may be an issue for large-scale server clusters, which usually rely on a relational database for network storage of -sessions. Support database storage of sessions is planned for a -future release.</P> +sessions. Support for database storage of sessions is planned in a +future release. In the meantime, instructions are provided for +hooking up to Apache::Session.</P> <P> <H2><A NAME="text::template">Text::Template</A></H2> +<P><A HREF="http://search.cpan.org/search?dist=Text-Template">http://search.cpan.org/search?dist=Text-Template</A></P> <P>This module has become the de facto standard general purpose templating module on CPAN. It has an easy interface and thorough documentation. The examples in the docs show a pipeline execution @@ -672,6 +685,7 @@ e-mails, PDFs, etc.</P> <P> <H2><A NAME="template toolkit">Template Toolkit</A></H2> +<P><A HREF="http://template-toolkit.org/">http://template-toolkit.org/</A></P> <P>One of the more recent additions to the templating scene, Template Toolkit is a very flexible mini-language system. It has a complete set of directives for working with data, including loops and @@ -744,6 +758,7 @@ collection of documents.</P> <P> <H2><A NAME="html::template">HTML::Template</A></H2> +<P><A HREF="http://search.cpan.org/search?dist=HTML-Template">http://search.cpan.org/search?dist=HTML-Template</A></P> <P>HTML::Template is a popular module among those looking to use a mini-language rather than in-line Perl. It uses a simple set of tags which allow looping (even on nested data structures) and conditionals @@ -775,6 +790,7 @@ <P>And now, a few honorable mentions:</P> <P> <H2><A NAME="html_tree">HTML_Tree</A></H2> +<P><A HREF="http://homepage.mac.com/pauljlucas/software/html_tree/">http://homepage.mac.com/pauljlucas/software/html_tree/</A></P> <P>As mentioned earlier, HTML Tree uses a fairly unique method of templating: it loads in an HTML page, parses it to a DOM, and then programmatically modifies the contents of nodes. This allows it to @@ -785,18 +801,21 @@ is ``HTML_Tree'', not ``HTML::Tree''.</P> <P> <H2><A NAME="apache::xpp">Apache::XPP</A></H2> +<P><A HREF="http://opensource.cnation.com/projects/XPP/">http://opensource.cnation.com/projects/XPP/</A></P> <P>XPP is an in-line Perl system that compiles to bytecode. Although it is a perfectly good implementation, it has little to differentiate it except for an easy mechanism to define new HTML-like tags which can be used to replace in-line code in templates.</P> <P> <H2><A NAME="eperl">ePerl</A></H2> +<P><A HREF="http://search.cpan.org/search?dist=Apache-ePerl">http://search.cpan.org/search?dist=Apache-ePerl</A></P> <P>Possibly the first module to embed Perl code in a text or HTML file, ePerl is still a viable option in the form of Apache::ePerl. It caches compiled bytecode in memory to achieve solid performance, and some people find it refreshingly simple to use.</P> <P> <H2><A NAME="cgi::fasttemplate">CGI::FastTemplate</A></H2> +<P><A HREF="http://search.cpan.org/search?dist=CGI-FastTemplate">http://search.cpan.org/search?dist=CGI-FastTemplate</A></P> <P>This module takes a minimalistic approach to templating, which makes it unusually well suited to use in CGI programs. It parses templates with a single regular expression and does not support anything in