WebGUI has shipped with HTML::Template for a long time. It's sort of the de-facto standard for Perl templates, and many users already have it installed. It has a simple syntax that is reminiscent of HTML tags, and can present simple data structures with a minimum of fuss. So, what's the problem?
The first issue is the syntax: it looks like HTML. This is particularly an issue when you are templating an HTML page because it becomes difficult to visually separate the template parts from the markup parts. It also leads to constructs that look badly formed — for instance, the common
<a href='<tmpl_var name="some_url">'>Link Text</a>
Now I have what appears to be an unclosed HTML tag sitting in the middle of my href attribute. To be fair, HTML::Template does allow a "comment" template variable style:
<a href='<!-- tmpl_var name="some_url" -->'>Link Text</a>
But this is hardly an improvement, and still looks like HTML.
The second major issue with HTML::Template is its generally poor handling of data structures. At first glance, it seems to handle all three of the core Perl datatypes admirably: scalars become TMPL_VARs, arrays become TMPL_LOOPs, and hashes become... wait a moment. Don't I send hash references to templates all the time?
$self->processTemplate($id, {foo => 'bar', baz => 'qux'});
Well, not really. HTML::Template has no real way to talk about hashes (or scalars, depending on which way you look at it). A hash is a context. If you want to display some kind of associative information, you have to munge your data into a TMPL_LOOP (an array reference):
my $loop = [map {{ key => $_, value => $hash{$_} }} keys (%hash)];
Then you get to loop through this in your template:
<tmpl_loop my_hash_thing>
<tmpl_var key>
<tmpl_var value>
</tmpl_loop>
It also has no way to talk about raw values inside a loop. I cannot send [1,2,3,4] to HTML::Template. Each value must be a hashref with named variables, or it is useless to me, and thus it becomes:
my $array = [map {{ value => $_ }} @myArray];
This can become a real pain for more complicated data structures, and you shouldn't have to do it. A template should take whatever data I give it and extract the useful parts into a view. I shouldn't have to write code to prepare it for the template engine!
Luckily for us, Perl (both the language and the community) has this abiding maxim: there is more than one way to do it. WebGUI tries to share this attitude, so ever since somewhere in WebGUI 5, you can plug in a different templating engine. The only alternative (by default) is Template Toolkit, but all that is required to plug in your template engine of choice is a new subclass of WebGUI::Asset::Template::Parser. Add your new subclass to your WebGUI config file (under the templateParsers variable), and now you can use whatever template engine best fits the task at hand.
As a point of comparison (and to encourage you to make use of the already available and excellent Template Toolkit), here is a brief look at the Template Toolkit syntax:
$self->processTemplate(
$templateId, {
bare_array => [1,2,3,4],
hash => { foo => 'bar', baz => 'qux' },
url => 'http://www.google.com',
}
);
[% FOREACH number IN bare_array %]
$number
[% END %]
[% FOREACH item IN hash %]
[% item.key %]: [% item.value %]
[% END %]
<!-- or maybe you didn't want to loop? -->
Foo: [% hash.foo %]
Bar: [% hash.baz %]
<a href='$url'>Link Text</a>
Template Toolkit syntax doesn't look like HTML, and supports much richer data access than HTML::Template, far beyond the simple cases we've covered here. And if you have another templating engine that you prefer, it's almost trivial to leverage it from WebGUI. There is more than one way to do it!