[ZPT] Extracting macro content programitcally

Evan Simpson evan@zope.com
Fri, 21 Sep 2001 20:19:15 -0400


Clint Brubakken wrote:

> <html metal:use-macro="template">
> 	<span metal:fill-slot="article">
> 	blah
> 	</span>
> </html>
> 
> I want to be able to get everything between the 2 span tags what
> actually fills the  slot, via a python script, to catalog or what not.
> 
> Is this possible


Not without a fair bit of hackery.  You *could* look at the template's 
_v_program (requires an External Method or filesystem code to access) 
and drill your way down through the data structure to the slot, but it's 
fairly tangled in there.

Is this a general need (i.e. you want to grab whatever slots a template 
of unknown structure may have) or a special case sort of thing?  By that 
I mean, suppose instead of using <span> you wrote your slot like this:

<metal:slot1 fill-slot="article>blah</metal:slot1>

This is legal in ZPT, ignored about the same as 'span' by editors I've 
tried, and the 'slot1' part is ignored by METAL, so it can be anything.

You could then do string.split(rawtext, 'metal:slot1')[1][:-2] and trim 
off everything up to the first '>' to get "blah".  I realize that this 
is very ad hoc, but it might do what you want.

Cheers,


Evan @ Zope