[Grok-dev] Re: grok.PageTemplate and content types
Philipp von Weitershausen
philipp at weitershausen.de
Thu Jan 11 10:33:26 EST 2007
Jan-Wijbrand Kolman wrote:
> 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
I already did this in grok svn, so that changes to filesystem ZPTs
wouldn't require a Zope 3 restart.
> 2) Sniff the template content in grok.components.PageTemplate.__init__
> and to set the content_type attr on the instance accordingly.
We could make this quite explicit using the file extension, for example.
'foo.pt' would be text/html and 'foo.xpt' would be text/xml.
--
http://worldcookery.com -- Professional Zope documentation and training
2nd edition of Web Component Development with Zope 3 is now shipping!
More information about the Grok-dev
mailing list