Craig Barratt wrote:
...
> The philosophy section in the Text::Template pod certainly resonates
> with me:
>
> > Philosophy
> >
> > When people make a template module like this one, they
> > almost always start by inventing a special syntax for
> > substitutions. For example, they build it so that a string
> > like `%%VAR%%' is replaced with the value of `$VAR'. Then
> > they realize the need extra formatting, so they put in some
> > special syntax for formatting. Then they need a loop, so
> > they invent a loop syntax. Pretty soon they have a new
> > little template language.
> >
> > This approach has two problems: First, their little language
> > is crippled. If you need to do something the author hasn't
> > thought of, you lose. Second: Who wants to learn another
> > language? You already know Perl, so why not use it?
> >
> > `Text::Template' templates are programmed in Perl. You
> > embed Perl code in your template, with `{' at the beginning
> > and `}' at the end. If you want a variable interpolated,
> > you write it the way you would in Perl. If you need to make
> > a loop, you can use any of the Perl loop constructions. All
> > the Perl built-in functions are available.
>
> However, I find that TT is a big help in balancing the partitioning
> of presentation logic and application logic, and its flexibility and
> extensibility more than make up for the disadvantage of a (simple)
> new language.
I prefer the TT concept because I'm letting users create and edit
their own templates. If I allow perl code in the template then
security goes out the window. With TT I can store the templates
in a DB (with my own provider), not allow perl code while still
allowing all sort of useful plugins, and especially useful: I can
write my own functions which are private, but make them available
to users in their own templates. They only know the name and what
it does and can use it freely but safely for the system.
Cheers
Robert