I’ve done a similar thing, albeit in a very different circumstance (having “templates” within templates, that get sent with an ajax-form and populated by a response from CGI::Ajax, sent back to the dom, and stuck in wherever they are supposed to go). In this case, I need to keep the <TMPL_VAR WHATEVER> information in that format, so when the template-chunk gets sent back to perl, it can be seen as such, filled in as necessary, and returned as a populated template.  To accomplish this, I rewrite any and all tmpl_vars within a certain div id, something like $div_html = s/<(\/?)TMPL_(.*?)\s*(.*?)> /__$1TMPL_$2 $3__/ig  (turning < and > into __ ) and then rewrite this upon receiving the template-chunk, before parsing it.

It works well enough, although it is a bit nasty introducing randomly-chosen syntax...

On 7/28/08 5:29 PM, "city crew" <city__crew@hotmail.com> wrote:

> Date: Mon, 28 Jul 2008 17:13:58 -0400
> Subject: Re: [htmltmpl] Leaving tmp_var intact inside template
>
> city crew wrote:
>
> > 2. store template output into a scalar and to a regexp subst on the
> > scalar before printint that to the file.
> >
> > my $templateRef = $template->output;
> > $templateRef =~ s/&lt;TMPL_/<TMPL_/g;
> > print TEMP $templateRef;
> >
> > As I am writing this I think I'm going to go with solution 2 as it
> > outputs the file and doesn't require any filter on loading the second
> > template.
>
> We do something similar to your #2. We use a slightly more obvious
> syntax though. We use <
TMPL_VAR> for things that are being loaded on the
> first pass and <DYN_VAR> for things on the 2nd pass.

I like that, I was experimenting with !TMPL_VAR but yours seems more semantically appealing. (I'm practicing my impressive technical speak there...)
 
>
> Just FYI, I've heard this technique named a couple of different things,
> in case you want to impress anyone :) It's usually called "2 pass
> templating" or "Write-thru cache templating".
 
Nice! I'll try impress my wife with "Write-thru cache templating", maybe I'll get lucky. =o)
 
Grant

>
> --
> Michael Peters
> Plus Three, LP
>



Click here. Want to help Windows Live Messenger plant more Aussie trees? <http://livelife.ninemsn.com.au/article.aspx?id=443698>