[Grok-dev] grok.PageTemplate and content types

Jan-Wijbrand Kolman janwijbrand at gmail.com
Thu Jan 11 06:23:36 EST 2007


Hi,

grok.PageTemplate subclasses from
zope.pagetemplate.pagetemplate.PageTemplate which by default treats
the template's source as text/html. As a result the HTMLTALParser is
used for compiling the template code, which can lead to problems if
you want to use proper XML (like XHTML). For example, the
HTMLTALParser does not allow for a closing </link> tag. Ugh.

Anyway, zope.pagetemplate.pagetemplatefile.PageTemplateFile deals with
this by sniffing the template's file contents to determine whether
it's dealing with XML or not. If it is, it makes sure the content_type
attr for the template instance is set to 'text/xml' and thus the
'TALParser' is used for compiling the template code,

I can see two solutions:

1) Make use of zope.pagetemplate.pagetemplatefile.PageTemplateFile in
grok.templatereg.TemplateRegistry if it is dealing with filesystem
templates, or

2) Sniff the template content in grok.components.PageTemplate.__init__
and to set the content_type attr on the instance accordingly.

What do you think?

regards,
jw

-- 
Jan-Wijbrand Kolman


More information about the Grok-dev mailing list