[htmltmpl] Config bits within templates
Brought to you by:
samtregar
From: Karen J. C. <si...@ph...> - 2003-12-10 03:37:19
|
This is the sort of thing I was thinking of... it's quick and dirty (*very* dirty), and really not worth even making into a module, but I did, at least in theory (I haven't used it yet, and may never... I can't actually remember the circumstances in which I thought it might be useful). It stomps all over any ability to use caching and whatnot, but that's okay for me because anything that's using caching is already connected to the database server and wouldn't need this sort of storage. It also doesn't make use of my suggestion to keep it enclosed in comment boundaries, but it's really more of a "here's what I was talking about" sort of thing than a "this might be useful in this form" sort of thing. package HTML::Template::Config; use strict; use HTML::Template; sub new { # file my $class = shift; my $filename = ""; for (my $i = 0; $i <= $#_; $i += 2) { if (lc($_[$i]) eq "filename") { $filename = $_[$i+1]; splice @_, $i, 2; last; } } open FILE, $filename; my @template = <FILE>; close FILE; my $template_param; while ($template[0] =~ /^(\w+?)\=(.+)$/) { $template_param->{$1} = $2; shift @template; } return wantarray ? (HTML::Template->new(arrayref => \@template, @_), $template_param) : HTML::Template->new(arrayref => \@template, @_); } 1; Templates would go something like: fred=foo bar=baz <HTML><TMPL_VAR blah blah blah... -- Karen J. Cravens si...@ph... |