Re: [htmltmpl] variable inside a variable
Brought to you by:
samtregar
From: Jonathan L. <dat...@gm...> - 2006-10-04 03:39:16
|
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 |