perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From David Nicol <>
Subject Re: is there a templating system that....
Date Fri, 12 Aug 2005 20:45:04 GMT
On 8/12/05, Jonathan Vanasco <> wrote:
> If/else and loops are already 'too much' -- I essentially just want
> variable substitution.  I want designers to be able to work on a page
> and not need to know anything about the  code/logic.  Names go here,
> dates go here, etc.   I have a bunch of custom mod_perl stuff that
> handles everything right now. I just want to split the code out of the
> handler routines.

Just pick a naming convention and run what you get back from the 
designers through the substitution operator.  I like square brackets
around the variable names, since that convention has some history.

     my $output = $TemplateCache{$template_name};
     $output =~ s/\[(\w+)\]/$InsertableVariables{$1}/g;
     print $output;

If all you want is variable substitution, just do variable substitution.

If you trust your page designers, have them use dollar-signs instead
of square brackets and things get even easier, with the insertables
as perl variables in your scope:

     $output = eval << "EOE";

It is not possible to define an abstraction around these tools that
isn't more trouble than its worth, which is why there is no
on CPAN, although it might be appropriate in Acme::.

I have defined subroutines such as

     sub print_template($$){
          my ($template, $hashref) = @_;
          ref $hashref or croak "usage: print_template($template, $hashref);
          $template =~ s/\[(\w+)\]/$hashref->{$1}/g;
          print $template;

and used them repeatedly within perl-driven logic, to print table lines
defined with a template, for instance.

You have to parse the repeated parts out of what your page designer gives you
somehow, but I expect you're going to have to massage your designer's output
even if you use a templating engine with its own control flow.

SSI sounds like PHP.

View raw message