Re: TMPL_XXX idea SCOPE

Sam Tregar <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.html-template
Message-ID <[email protected]>
On Tue, 1 Mar 2005, Robert Ferney wrote:

> I envision something like
> <TMPL_SCOPE NAME="other">
>     <div style="color:<TMPL_VAR color>;"><TMPL_VAR name="bar"></div>
> </TMPL_SCOPE>
> 
> this would be a slight variation on the TMPL_LOOP with the main
> difference being that there is only one of them, rather than a list of
> them.. ie.. it's going to get a HASH ref instead of a LIST ref that
> contains HASH refs.
> 
> I'm looking at the code now, I don't think this should be *too*
> difficult. but any time you have to grok someone elses code it is
> going to take longer than it would someone who is already familiar
> with it.

I think this could be done relatively easily in a sub-class using
filter and an overridden param().  Here's how:

  - Your custom filter parses the SCOPEs and find VARs inside them.
    It alters their names to include the SCOPE name.  For example, a
    var named "foo" inside a scope called "bar" might be "foo...bar".

  - Your custom param() looks for hash-refs and similarly modifies
    their names into "scope...var" format.

  - For extra credit, catch exceptions and fix the names so they don't
    expose the grotty internals to the end user.

-sam


-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
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.