Designer-friendly HTML::Template templates

dws on 2003-03-07T19:46:54

The Silicon Valley Perl Mongers did lightning talks earlier this week. It was short notice, attendance was very light, and only a few people had talks. Still, it was a fun evening. Fun enough that we'll repeat it (with more warning, I hope).

I gave two short talks. One was on the rather evil trick of using nested regexes to handle a class of substitution problems. The other talk was more practical, dealing with the challenge of sharing responsibility for templatized pages with a non-programmer designer. In brief, the idea is to make templates directly viewable in browsers, so that designers can verify their designs and design changes without having to run a tool to expand the template. (Such tools always seem to be broken at the moment a designer needs them.) From the development perspective, the designer leaves "example" fragments in the code that need to be replicated by some use of the template.

The technique for isolating "example" fragments such that they're visible when the template is viewed in a browser, but invisible when the template is expanded, is pretty simple.

$template->param(EXAMPLE => 0);
...
<TMPL_IF EXAMPLE> HTML fragment </TMPL_IF>

The browser ignores the unknown tags, and shows the fragment. When the template is expanded, the fragment goes away.

The second step--replacing the fragement with other stuff--is also pretty simple.

$template->param(BEGIN => "-->);
$template->param(END => "<--");
...
<!-- <TMPL_VAR BEGIN> template stuff <TMPL_VAR END> -->

The template stuff is invisible to the browser, but visible when expanded.

Then it's a *cough* simple matter of keeping development changes in sync with design changes.