[ZPT] Using METAL to access a macro outside PT rendering

Francis Potter francis@helium.com
Fri, 14 Dec 2001 20:10:28 -0800


I want to extract a macro from a Page Template within Python. Let's
assume it doesn't have any slots and it doesn't have any TAL.

If mypt is the PageTemplate object and I want the macro called mymacro,
then I can do this...

tempString = '<span metal:use-macro="options/x/macros/mymacro"/>'
tempPT = PageTemplate.PageTemplate()
tempPT.write(tempString)
result = tempPT(x=mypt)

...and "new" is a string containing the contents of the macro.

But this seems very indirect. Is there a simpler way, maybe one which
doesn't involve actually building a separate PageTemplate object? What I
really want is to be able to say something like:

x.extractMacro("test")

Something I'm missing?

--- Francis Potter