Derek Broughton wrote:
::
No, I really don't care what content type header is sent back - I suspect
text/html for the content type might work, but that's well beyond my current
problem. My problem is that TAL, not my browser, is treating the template
as HTML rather than XML and therefore lowercases all the tags (using
HTMLParser.py).
Sorry, I misunderstood your question then. I suspect you still want to
set the response header, but more on that later.
A little debugging shows me that the problem is in using the viewlet. My
main view template, Text.pt, starts with<?xml... and is treated as XML. My
viewlet, _cannot_ start with<?xml (generates an error "XML Parsing Error:
XML or text declaration not at start of entity" if I add it).
I would perhaps think that using viewlets to compose an XML document is
not something viewlets were designed for. You may have more luck just
building the document using the tools that come with lxml, although this
will be more imperative and less template-like.
I put some prints in Products/PageTemplates/PageTemplateFile.py:
def sniff_type(text):
print __name__, 'sniff', text
if text.startswith('<mcp:MD_Meta'):
raise
for prefix in XML_PREFIXES:
if text.startswith(prefix):
return "text/xml"
return None
and find that I get two prints:
Products.PageTemplates.PageTemplateFile sniff<?xml versio
Products.PageTemplates.PageTemplateFile sniff<mcp:MD_Meta
The first is from Text.pt - which is recognized as xml - and the second is
the first line of the viewlet template, and gets treated as html.
I traced back that call, and found in _exec():
if not response.headers.has_key('content-type'):
response.setHeader('content-type', self.content_type)
so, yes, really, content_type should be settable in the view, somewhere, and
pulling out all my other code changes it seems that it _does_ work for the
_View_, but not for the _Viewlet_. The only thing that actually seems to
set "text/xml" for the viewlet is that "sniff_type()" call and afaict it
can't possibly be right - surely the type of a viewlet must always be the
type of it's parent view?
Meanwhile, I haven't found anything that will work for a viewlet, so for
now, I'm going to just pull it out and duplicate the code in the two View
templates that were using it.
Maybe instead of using viewlets, you could use ZPT macros? I assume that
the ZPT parser would read the whole ZPT file and so you coul dhave a
<?xml ..> header in both, but obviously only the bits inside the
metal:define-macro would actually be pulled in.
Martin
--
Author of `Professional Plone Development`, a book for developers who
want to work with Plone. See http://martinaspeli.net/plone-book
_______________________________________________
Product-Developers mailing list
[email protected]
http://lists.plone.org/mailman/listinfo/product-developers