[Grok-dev] Re: grok.PageTemplate and content types
Philipp von Weitershausen
philipp at weitershausen.de
Fri Jan 12 13:13:41 EST 2007
Martijn Faassen wrote:
> Jan-Wijbrand Kolman wrote:
>> (ouch, I replied to Philipp initially, not to the list. Here is it again)
>>
>>> >> 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.
>>> >
>>> > That's too big of a change;
>> <snip>
>>
>> I agree. Actually, I was wondering about the "dependency" on the *.pt
>> extension altogether. But that's for some other time.
>
> I have the idea to support other templating languages by allowing files
> with other extensions in there, eventually.
>
>>> > Is the sniffing too magic? Do people trip up because of this in Zope?
>>>
>>> Well, it used to be that you had to add the <?xml ?> processing
>>> instruction to a template file to enforce the XML parser. This made it
>>> pretty much impossible to use the XML parser for XHTML documents because
>>> IE goes into quirks mode when it sees <?xml ?>.
>>
>> Ah, good point, I didn't realise that...
>>
>>> I'm pretty sure that zope.pagetemplate.pagetemplatefile still uses that
>>> sniffing algorithm.
>>
>> Yes it is.
>>
>> What about begin able to do this:
>>
>> class Foo(grok.View):
>> grok.template('specialfoo', mime_type='application/xml')
>>
>> and
>>
>> grok.PageTemplate("""\
>> <html>
>> ...
>> </html>
>> """, mime_type="application/xml")
>>
>> Would that work? We still need to find a reasonable default of course...
>
> Do I understand it correctly that the goal here is to control the output
> mime type?
Not entirely. I think the initial goal was to explicitly specify which
parser (HTML or XML) the ZPT engine would use. That was at least JW's
problem.
> I wonder whether we don't simply want to support a
> grok.mime_type directive on views (and your solution for the inline page
> templates). Such a separate directive allows view subclassing and such,
> which your grok.template doesn't support, I think.
No need for a mime type directive, you can always do
response.setHeader('Content-Type', 'text/xml') from anywhere in your
view. Or perhaps I'm misinterpreting what problem this grok.mime_type
directive is supposed to solve.
To solve JW's problem, we really just need an explicit way to specify
the parser type in ZPTs. I suggested file extensions, JW suggested a
parameter when instantiating templates. I think a solution somewhere
along or between those lines can be found.
--
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