Download - Choosing a Templating System
Perrin Harkins
The Ultimate Templating SystemThe Ultimate Templating System
$HTML =~ s/\$(\w+)/${$1}/g;
FOR MORE INFO...
Contact Harkins Enterprises for licensing information. Excellent per-CPU pricing available.
Why bother?Why bother?
Consistency of appearanceReusabilityBetter isolation from changesDivision of labor
Template TaxonomyTemplate Taxonomy
Execution modelLanguageParsingFramework or just templates
Execution ModelExecution Model
Callback– Mason, Embperl, Apache::ASP
mod_perl
Perl space
template
Execution ModelExecution Model
Pipeline– HTML::Template, Template Toolkit
mod_perl Perl space template
CallbackCallback
Pro– Easy to componentize pages– Quick to get started with
Con– Messy for branching
PipelinePipeline
Pro– Handles branching cleanly– Possible tuning opportunities
Con– Slower to get started with
LanguageLanguage
Burn baby burn– in-line Perl– mini-languages
In-line Perl sampleIn-line Perl sample
<% my $product = Product->load('sku' => 'bar1234'); %>
<% if ($product->isbn) { %>
It's a book!
<% } else { %>
It's NOT a book!
<% } %>
<% foreach my $item (@{$product->related}) { %>
You might also enjoy <% $item->name %>.
<% } %>
Mini-language sampleMini-language sample
[% USE product(sku=bar1234) %]
[% IF product.isbn %]
It's a book!
[% ELSE %]
It's NOT a book!
[% END %]
[% FOREACH item = product.related %]
You might also enjoy [% item.name %].
[% END %]
ParsingParsing
CompiledCached parse treeRepeated parse
template Perl codecompiledbytecode
Frameworks vs. Just TemplatesFrameworks vs. Just Templates
URL mappingSession trackingOutput cachingForm handlingDebuggingOther options
– libservlet, Apache::PageKit, OpenInteract, CGI::Application
The ContendersThe Contenders
SSI HTML::Mason HTML::Embperl Apache::AxKit Apache::ASP Text::Template Template Toolkit HTML::Template
SSISSI
CallbackMini-languageRepeated Parse#perlApache::SSI for filtering
HTML::MasonHTML::Mason
Callback (mostly) In-line Perl Compiled Publishing roots<%init> Caching Parameter checking Debug files
Text::TemplateText::Template
CallbackIn-line PerlCompiledSafeIncludes not includedCache it yourself
Apache::ASPApache::ASP
Callback In-line Perl Compiled Built-in objects URL-munging sessions XMLSubs, XSLT
<site:header page="Page Title" /> Sticky widgets Compressed output No RDBMS session storage built in
Apache::AxKitApache::AxKit
Pipeline (usually) Mini-language or in-line Perl Compiled Stylesheet
– XML::XSLT, XML::Sablotron, XPathScript Provider
– XSP, XSP taglibs Caching Compression
HTML::EmbperlHTML::Embperl
Callback In-line Perl Compiled Safe%fdat, %udat HTML support
– TABLE, INPUT, query strings, etc. EmbperlObject Control structures
Template ToolkitTemplate Toolkit
Pipeline (sorta) Mini-language Compiled Dot notation: foo.bar.baz Macros Filters Plugins
– XML, DBI– Dates, prices, multi-column
ttree, Splash library
HTML::TemplateHTML::Template
PipelineMini-languageCached Parse TreeFast and simpleTemplates can be cached in shared
memory or disk
Honorable mentionsHonorable mentions
ePerlApache::XPPCGI::FastTemplateHTML_Tree
PerformancePerformance
Don’t start with your templating system!
Benchmarks– http://www.chamas.com/bench/hello.tar.gz
CGI concerns
Frameworkor Just Templates
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
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 Callback Compiled Perl