[Grok-dev] Re: grok.PageTemplate and content types

Philipp von Weitershausen philipp at weitershausen.de
Thu Jan 11 10:38:32 EST 2007

Gary Poster wrote:
>> 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.
> 3) make connecting templates more explicit :-D
> Thanks for all the replies to the thread I started, btw; I particularly 
> plan to reply to Martijn's thoughtful post ASAP.

At least we should consider the ability of specifying a particular 
content type explicitly. As Martijn pointed out nicely, grok typically 
lets you be quite explicit, but it has sensible defaults. One thing grok 
certainly doesn't do is just guess, which is why I'm not a big fan of 
the sniffing.

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