Re: variable inside a variable

"Jonathan Lang" <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.html-template
Message-ID <[email protected]>
Matthew wrote:
> Is it possible to have a variable inside a variable be parsed?
>
> I'd like to pull some text from DB containing a few tmpl_var's and
> assign that text to a tmpl_var in original file I instantiated the
> object with.
>
> Is this possible?

HTML is very specific as to what it allows: when you pass a variable
into the template, you have to bear in mind which tag the variable is
going to be used in.  A tmpl_var can only receive a string or a
number; I'm not even sure if it's permitted to take a boolean value,
although it might be.  A tmpl_if/tmpl_unless can only receive a
boolean value.  A tmpl_loop can only receive a list of hashes, and
tags nested within it access hash keys of the current iteration of the
loop instead of other variables passed into the template.  There's a
flag you can use that lets nested tags access global variables as
well, as long as none of the hash keys clobber that name.

But there's no way to pass a simple hash or list into the template;
the _only_ aggregate data that HTML::Template handles is the list of
hashes used by tmpl_loop.  Since tables are not a native data type for
perl, this makes it awkward for programmers to pass loop data into the
template; but then, HTML::Template seems to have a design philosophy
of keeping the template syntax as simple as possible at _all_ costs.
HTML::Template::Expr relaxes the straitjacket somewhat; but even that
much flexibility is viewed by the designer as a neccessary evil.

-- 
Jonathan "Dataweaver" Lang

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.