[Templates] how do I find all parsed tags?
Blue Eyed Devil
eyed_devil_blue at hotmail.com
Tue Jul 1 03:27:15 BST 2008
Thanks for your thoughts.
In this case you would set BOY as you normally would. It would thus be set in the stash (or collection of all tags) so when you want to retrieve all tags it would be part of the collection. This would of course not form any problem since in this case we already know what value we want to assign to the tag (similar to the concept of prototyping that I decided to go with). So when the document gets processed you know this much already...
The problem however is when you don't know what tag will be in the document !
This is where the issue comes up of being able to ask TT "what tags did you find in the document?", so you can then say "Oh, there is a PAGEID tag... gee I didn't foresee this, but maybe my custom AUTOLOAD function can cleverly put in a message to let the user know a tag is being ignored"... or another scenario could be "I would like to keep statistics of all my users what tags they intuitively use in their templates that are not supported". These are just some examples I can think of where knowing what tags were parsed and not processed can come handy.
Again, not something someone would need on a daily basis, but I feel this is something that should be supported for sake of completion. Maye one could correlate this with namespaces, where you can loop through let's say ${$main::*} and know what's out there for you to manipulate... does a normal Perl scripter need this? No, but every now and then an advanced user will want this capability to do something quite specific.
Your example did make me think, and I realized I should maybe specify that only variable names would probably make sense to have in a globally accessible property/method. So even if a complex IF tag would be encountered, it would only store the variable in the condition (i.e. BOY) since this is really what we are interested in manipulating. Once another template would fire off (via PROCESS let's say), the whoe process would start anew for that template's "namespace" and it would now create a tag collection of all tags found on that particular template, and so on and so on...
Maybe other people can think of other uses for this to where maybe the developers of TT would consider implementing this relatively simple feature.
Again, thanks Bill !
Milan> Date: Mon, 30 Jun 2008 17:56:43 -0700> From: moseley at hank.org> To: templates at template-toolkit.org> Subject: Re: [Templates] how do I find all parsed tags?> > On Mon, Jun 30, 2008 at 11:31:31AM -0400, Blue Eyed Devil wrote:> > > > My question is whether or not TT has an option to know all the tags> > it was able to parse and retrieve those?> > > > Example:> > > > [% BOY %] says [% WORD %] to [% GIRL %]> > > > Let's say I pass in the vars, BOY and WORD to $template->process()> > but NOT the var GIRL. However, I would like to have the ability to> > do something like:> > > > @tags = $template->some_method();> > > > And when I would go through the @tags it would contain ('BOY',> > 'WORD', 'GIRL').> > > And what if your template has:> > IF BOY == 'George';> PROCESS templates/george.tt;> ELSE;> PROCESS templates/typical_boy.tt;> END;> > So you can't know what variables you need until you actually process the> template and you don't know what template to process until you set> those variables.> > > > -- > Bill Moseley> moseley at hank.org> Sent from my iMutt> > > _______________________________________________> templates mailing list> templates at template-toolkit.org> http://mail.template-toolkit.org/mailman/listinfo/templates
_________________________________________________________________
The other season of giving begins 6/24/08. Check out the i’m Talkathon.
http://www.imtalkathon.com?source=TXT_EML_WLH_SeasonOfGiving
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.template-toolkit.org/pipermail/templates/attachments/20080630/62cd1a1f/attachment-0001.htm
More information about the templates
mailing list