Re: [htmltmpl] get value from template?
Brought to you by:
samtregar
From: Mathew R. <mat...@re...> - 2004-11-04 07:13:33
|
> I'm looking for suggestions on how to get a value from my template = that can=20 > be used in my Perl code. I'd rather not switch to another template = module=20 > that would provide this since HTML::Template has otherwise met my = needs. >=20 > The details... >=20 > In my template, I'd like to have something like: >=20 > <TMPL_VAR NAME=3D"QUERY" VALUE=3D"SELECT col1, col2 FROM table"> >=20 > and then do something like this in my Perl code: >=20 > my $template =3D HTML::Template->new(filename =3D> 'test.tmpl'); > my $value =3D $template->param('QUERY'); >=20 > and have $value =3D "SELECT col1, col2 FROM table" umm... why? What benefit does this give you? What kind of output are = you expecting from the TMPL_VAR? ... its not clear how this requirement would be all that useful... or = would even make sense in the context of "seperation of code and = presentation" that H::T provides... > My three thoughts are: >=20 > 1. use a filter, but I don't know how to get $template instead of the = filter=20 > subroutine so I can call $template->param to set the value. The only = thing=20 > passed to the filter subroutine is the text of the file and not $self? >=20 > 2. extend HTML::Template to handle this via the existing TMPL_VAR or = add a=20 > new tag TMPL_DEFINE >=20 > 3. Use HTML::Template::Expr, but my experience is that ::Expr is slow = and I=20 > don't need all the other features it would provide. Using H::T::E sounds like the best solution... Mathew |