Hi, I need to render a string (not a zpt-object) with tales like <img tal:attributes="src here/images/spacer.gif/absolute_url" src="spacer.gif" alt="" title="" border="0" width="1" height="15" />. Does anybody know how to do this in a script? I already know how to import PageTemplate.py and it should work with read() or pt_render() or document_src() but it does'nt. :( I get unauthorized errors. -- many thanks for your replies, Elena
Elena Schulz wrote at 2003-1-8 15:51 +0100:
... I need to render a string (not a zpt-object) with tales like <img tal:attributes="src here/images/spacer.gif/absolute_url" src="spacer.gif" alt="" title="" border="0" width="1" height="15" />.
Does anybody know how to do this in a script? I already know how to import PageTemplate.py and it should work with read() or pt_render() or document_src() but it does'nt. :( I get unauthorized errors. Not a very big problem in an External Method:
You create a Zope Page Template object, wrap it into a context (using its "__of__" method) and then call it. Few chances in an (internal) Python Script, as you will not be allowed to call "__of__". Without this "__of__", the template has no way to know its context (e.g. "here", "container", ...). Dieter
Hi Dieter, thanks a lot
You create a Zope Page Template object, wrap it into a context (using its "__of__" method) and then call it.
You mean by the following? #creating: myZPT = Products.PageTemplates.ZopePageTemplate(id=myId, text=myZPTString, content_type=?) #wrapping: I did not find any __of__ method!? (Sorry my understanding of this needs some more enlightment myZPT=context.myZPT #calling: return context.myId() What to use for content_type? text/html? or better keeping the default? -- many thanks for your great help, Elena you wrote:
Not a very big problem in an External Method:
You create a Zope Page Template object, wrap it into a context (using its "__of__" method) and then call it.
Few chances in an (internal) Python Script, as you will not be allowed to call "__of__". Without this "__of__", the template has no way to know its context (e.g. "here", "container", ...).
Dieter
Elena Schulz wrote at 2003-1-9 11:06 +0100:
You create a Zope Page Template object, wrap it into a context (using its "__of__" method) and then call it.
You mean by the following? #creating: myZPT = Products.PageTemplates.ZopePageTemplate(id=myId, text=myZPTString, content_type=?) Yes. #wrapping: I did not find any __of__ method!? (Sorry my understanding of this needs some more enlightment Read about acquisition, e.g. in <http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html> maybe, in the Zope Developer Guide.
"__of__" is a method of "Acquirer", inherited by "ZopePageTemplate".
myZPT=context.myZPT myZPT= myZPT.__of__(context) # wrap it #calling: return context.myId() return myZPT() # render it
What to use for content_type? text/html? or better keeping the default? You can use "text/html" and "text/xml".
When you use "text/xml" "text" must be a well formed XML document and the "tal/metal" namespaces must be defined. Thus, you will probably prefer "text/html". Dieter
participants (2)
-
Dieter Maurer -
Elena Schulz