Interpreting dynamically generated TAL
Hi, it's me again, this time trying to interpret dynamically generated TAL (yes, we convinced our customer to go TAL, at least in this point. The setting: we generate TAL from a source XML via XSLT. Now we want to render it. I had a look into PageTemplates.py, and that's what I've come up with: | def edit_zpt(self, REQUEST = None, RESPONSE = None, | extra_bindings={}, | ishtml=1, | ): | """ | Whack Art. | """ | | # Snarfgled from $(ZOPEDIR)/lib/python/Products/PageTemplates/PageTemplate.py | text = self.edit(REQUEST, RESPONSE) | | # ---------------------------- compile template: | gen = TALGenerator(getEngine(), not ishtml) | if ishtml: parser = HTMLTALParser(gen) | else: parser = TALParser(gen) | errors = () | try: | parser.parseString(text) | program, macros = parser.getCode() | except: | raise PTRuntimeError, 'Page Template %s has errors: [%s: %s]' \ | % ((self, ) + sys.exc_info()[:2]) | warnings = parser.getWarnings() | # ---------------------------- get Zope context: | c = {'template': self, | 'options': {}, | 'nothing': None, | 'request': None, | 'modules': ModuleImporter, | } | parent = getattr(self, 'aq_parent', None) | if parent is not None: | c['here'] = parent | c['container'] = self.aq_inner.aq_parent | while parent is not None: | self = parent | parent = getattr(self, 'aq_parent', None) | c['root'] = self | c.update(extra_bindings) | output = StringIO() | TALInterpreter(program, macros, | getEngine().getContext(c), | output, |# debug=1, | )() |#### FIXME: what do we do with those? ## tal=not source, strictinsert=0 ## | return output.getvalue() The compiler seems happy, the interpreter doesn't barf either, but it doesn't replace a thing. It passes input verbatim to output. Am I missing anything obvious? Am I trying --again-- the impossible? Thanks for any pointers -- tomas
tomas@fabula.de wrote:
|#### FIXME: what do we do with those? ## tal=not source, strictinsert=0 ## | return output.getvalue()
The compiler seems happy, the interpreter doesn't barf either, but it doesn't replace a thing. It passes input verbatim to output. Am I missing anything obvious? Am I trying --again-- the impossible?
Looks good to me. Hmm. The 'tal' argument indicates whether to execute TAL code, but it is true by default. The 'strictinsert' argument controls whether text inserted by tal:replace and tal:content is parsed and compiled, and should probably be set false. Are you testing with 'ishtml' true or false? When it is false, you'll need to make sure that your XML contains the TAL namespace declaration. Cheers, Evan @ 4-am
On Wed, Sep 04, 2002 at 01:10:37PM -0500, Evan Simpson wrote:
tomas@fabula.de wrote:
|#### FIXME: what do we do with those? ## tal=not source, strictinsert=0 ## | return output.getvalue()
The compiler seems happy, the interpreter doesn't barf either, but it doesn't replace a thing. It passes input verbatim to output. Am I missing anything obvious? Am I trying --again-- the impossible?
Looks good to me. Hmm. The 'tal' argument indicates whether to execute TAL code, but it is true by default. The 'strictinsert' argument controls whether text inserted by tal:replace and tal:content is parsed and compiled, and should probably be set false.
Ahh. Thanks for the clarifications.
Are you testing with 'ishtml' true or false? When it is false, you'll need to make sure that your XML contains the TAL namespace declaration.
'ishtml' is set to false in our case. Thank you very much for your help. THe next thing I'll try is to set 'tal' explicitily to true. Who knows... Regards -- tomas
Evan Simpson <evan@4-am.com> wrote:
tomas@fabula.de wrote:
'ishtml' is set to false in our case.
...and your top-level element has the proper 'xmlns:tal=...' declaration in it?
Heh :-) This one got me too. I spent close to 30 minutes once figuring why a piece of xml didn't get its TAL evaluated. In XML mode you must always declare the namespaces for tal or metal for them to be parsed and evaluated... Florent -- Florent Guillaume, Nuxeo (Paris, France) +33 1 40 33 79 87 http://nuxeo.com mailto:fg@nuxeo.com
On Sat, Sep 07, 2002 at 04:24:54PM +0000, Florent Guillaume wrote:
Evan Simpson <evan@4-am.com> wrote:
tomas@fabula.de wrote:
'ishtml' is set to false in our case.
...and your top-level element has the proper 'xmlns:tal=...' declaration in it?
Heh :-) This one got me too. I spent close to 30 minutes once figuring why a piece of xml didn't get its TAL evaluated.
In XML mode you must always declare the namespaces for tal or metal for them to be parsed and evaluated...
Thing is, I've set HTML mode :-( I expect to have a longer debugging session in the next days. Stay tuned ;-) (Of course I'd still appreciate any hints/pointers/whatever). Thanks -- tomas
participants (3)
-
Evan Simpson -
Florent Guillaume -
tomas@fabula.de