Zope Page Template weirdness
Friday, October 14, 2005 at 4:20PM [code lang="xml"]
xxx
yyy
[/code]
both Andy and Kev asserted that it would render to:
[code lang="xml"]
xxx
yyy
[/code]
while I was asserting that it rendered to:
[code lang="xml"]
xxx
yyy
[/code]
(note the difference in the rendering of the 'selected' attribute of the
<option> tag.)I had distilled mine down from the MailManager code, as a test instance, whereas both Kev & Andy had created a fresh template in the ZMI. And both of us appeared to be right. We wondered if it was a difference in platform -- I'm working on my laptop, with python 2.4 & Zope 2.7.7. But no. The difference is that I'm rendering the files as content-type text/xml (which Zope kindly defaults to if it encounters a file starting
<?xml ... whereas they were forcing the content-type to text/html (the default if you create a template through the ZMI). If you force the content-type to text/xml in the ZMI you'll see the same results as I get.So it turns out that exactly the same Zope Page Templates will render slightly differently, depending on whether or not they are marked as being HTML or XML. Cool.
(I can understand why they are pulled apart by different parsers, since it's so much nicer to use a proper XML parser if you're expecting valid XML -- and leave the grotty excuses for HTML that one sometimes finds to another lame, hacky thing -- but to not mangle them into the same AST and use a unified generator at the other end?)
When I've got more time, I should go file bugs. But I've got an alpha of MailManager 2.1 to release this afternoon, so I'd better get on with that or there'll be no getting to go to the pub for me!
Reader Comments (1)
There is a recent thread on the zope-zpt mailing list about just this topic.
If you *need* HTML as output, rather than XHTML, then you *can't* allow the XML-isms to
get emitted; ZPTs HTML mode forces "empty" tags to have the extra space added, for
instance ('' instaead of '').
There may be a couple of others, mostly to do with working around "quirks mode" in the
browsers.