dynamically generated TAL not being interpreted
We have a script that generates TAL. The problem is that the content is not being interpeted as TAL by Zope, but rather as raw HTML. A search through the mailing lists archives found a posting from last September where someone was trying to do something similar. According to one of the replies, the HTML is supposed to have the TAL namespace declaration, so I changed my code to produce something like this at the top: <html xmlns:tal="http://xml.zope.org/namespaces/tal" metal:use-macro="here/main_template/macros/master"> But the problem persists. Does anyone know how I can do this? thanks, thomas -- N. Thomas nthomas@cise.ufl.edu Etiamsi occiderit me, in ipso sperabo
thomas since when have u become a zoppie. S. --- "N. Thomas" <nthomas@cise.ufl.edu> wrote:
We have a script that generates TAL. The problem is that the content is not being interpeted as TAL by Zope, but rather as raw HTML.
A search through the mailing lists archives found a posting from last September where someone was trying to do something similar. According to one of the replies, the HTML is supposed to have the TAL namespace declaration, so I changed my code to produce something like this at the top:
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
metal:use-macro="here/main_template/macros/master">
But the problem persists.
Does anyone know how I can do this?
thanks, thomas
-- N. Thomas nthomas@cise.ufl.edu Etiamsi occiderit me, in ipso sperabo
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
__________________________________________________ Do you Yahoo!? Yahoo! Tax Center - forms, calculators, tips, more http://taxes.yahoo.com/
N. Thomas wrote at 2003-3-1 23:46 -0500:
We have a script that generates TAL. The problem is that the content is not being interpeted as TAL by Zope, but rather as raw HTML.
A search through the mailing lists archives found a posting from last September where someone was trying to do something similar. According to one of the replies, the HTML is supposed to have the TAL namespace declaration, so I changed my code to produce something like this at the top:
<html xmlns:tal="http://xml.zope.org/namespaces/tal" metal:use-macro="here/main_template/macros/master">
But the problem persists.
Does anyone know how I can do this?
You cannot return TAL source code and expect it to be rendered. You must make a Page Template object from your TAL source code, wrap it in an appropriate context (--> "__of__") and return it (or call it to let it render). You can do this only in an External Method (or other filesystem based code). Dieter
* Dieter Maurer <dieter@handshake.de> [2003-03-03 20:56:46 +0100]:
N. Thomas wrote at 2003-3-1 23:46 -0500:
We have a script that generates TAL. The problem is that the content is not being interpeted as TAL by Zope, but rather as raw HTML.
You must make a Page Template object from your TAL source code, wrap it in an appropriate context (--> "__of__") and return it (or call it to let it render).
You can do this only in an External Method (or other filesystem based code).
Well, this was a start in the right direction. But after wading through the archives, the nearest solution I can cruft together is an external method like this: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate def talgen(): zptstr = \ """ <html> <body> If properlu rendered, this sentence <b tal:omit-tag="">should contain no tags.</b> </body> </html> """ zptid = 'foobar' z = ZopePageTemplate(id=zptid, text=zptstr, content_type="text/html") return z But this returns an error, probably because I'm stabbing in the dark. Also, I have no idea where exactly to stick the "__of__" method. (I did look at the relevant sections in http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html though.) My questions: Where is the API for Products.PageTemplates.ZopePageTemplate documented? In Products.PageTemplates, should I use PageTemplate, or PageTemplateFile, or ZopePageTemplate? In the code above, I see that ZopePageTemplate requires that an id be passed in, does that mean that I have to create a temporary ZPT object in the Zope filesystem, return that, and somehow make sure it is destroyed afterwards? I only passed in 'foobar' because it was required. Also, if anyone could point me to a fragment of code that does something similar it would be much appreciated. thomas -- N. Thomas nthomas@cise.ufl.edu Etiamsi occiderit me, in ipso sperabo
N. Thomas wrote at 2003-3-4 23:18 -0500:
* Dieter Maurer <dieter@handshake.de> [2003-03-03 20:56:46 +0100]:
N. Thomas wrote at 2003-3-1 23:46 -0500:
We have a script that generates TAL. The problem is that the content is not being interpeted as TAL by Zope, but rather as raw HTML.
You must make a Page Template object from your TAL source code, wrap it in an appropriate context (--> "__of__") and return it (or call it to let it render).
You can do this only in an External Method (or other filesystem based code).
Well, this was a start in the right direction. But after wading through the archives, the nearest solution I can cruft together is an external method like this:
from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
def talgen():
zptstr = \ """ <html> <body> If properlu rendered, this sentence <b tal:omit-tag="">should contain no tags.</b> </body> </html> """
zptid = 'foobar' z = ZopePageTemplate(id=zptid, text=zptstr, content_type="text/html") return z
But this returns an error, probably because I'm stabbing in the dark.
Because, you did not do the "__of__" magic... And, please remember, read error messages (Error Type, Error Values *AND* traceback) carefully and report them, if you do not understand them.
Also, I have no idea where exactly to stick the "__of__" method. (I did look at the relevant sections in http://www.dieter.handshake.de/pyprojects/zope/book/chap3.html though.)
Hm, you did not find the "__of__" mentioned in the "Name lookup section"? You use "return z.__of__(self)"
My questions:
Where is the API for Products.PageTemplates.ZopePageTemplate documented?
I am not sure, probably in the embedded online help. *BUT* you need nothing than the constructor (you already used) and the "__call__" method (that is trivial).
In Products.PageTemplates, should I use PageTemplate, or PageTemplateFile, or ZopePageTemplate?
As it is not a file in the file system, you do not use "PageTemplateFile" ;-) Almost surely, "ZopePageTemplate" is right. "PageTemplate" might work, too.
In the code above, I see that ZopePageTemplate requires that an id be passed in, does that mean that I have to create a temporary ZPT object in the Zope filesystem, return that, and somehow make sure it is destroyed afterwards? I only passed in 'foobar' because it was required.
No, unless you use special operations (e.g. "template/absolute_url") what you probably do not do.
Also, if anyone could point me to a fragment of code that does something similar it would be much appreciated.
You are very near :-) I trust you that you will write a HowTo about dynamic generation of TAL code, once you solved your problem ;-) Dieter
* Dieter Maurer <dieter@handshake.de> [2003-03-05 20:37:48 +0100]:
N. Thomas wrote at 2003-3-4 23:18 -0500:
* Dieter Maurer <dieter@handshake.de> [2003-03-03 20:56:46 +0100]:
N. Thomas wrote at 2003-3-1 23:46 -0500:
We have a script that generates TAL. The problem is that the content is not being interpeted as TAL by Zope, but rather as raw HTML.
You must make a Page Template object from your TAL source code, wrap it in an appropriate context (--> "__of__") and return it (or call it to let it render).
Well, this was a start in the right direction. But after wading through the archives, the nearest solution I can cruft together is an external method like this:
Because, you did not do the "__of__" magic...
Well, after banging my head on this for a few days, I was finally able to get this to work. Here is the correct code to do this: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate def talgen(self): zptstr = \ """ <html> <title>This is a dynamically generated ZPT page.</title> <body> This sentence <b tal:omit-tag="">should contain no tags.</b> </body> </html> """ z = ZopePageTemplate(id=None, text=zptstr, content_type="text/html") return z.__of__(self)() The problem earlier was that I was not defining the method with self so that it would be bound to the context, hence any references later on to self threw an error.
I trust you that you will write a HowTo about dynamic generation of TAL code, once you solved your problem ;-)
Yup, doing that now. It should be up on zope.org in the New User How-to section soon. Much thanks to Dieter Maurer, and hazmat (Kapil Thangavelu) on #zope (IRC freenode) for helping me out with this. thomas -- N. Thomas nthomas@cise.ufl.edu Etiamsi occiderit me, in ipso sperabo
participants (3)
-
Dieter Maurer -
N. Thomas -
vasanthsena x