Overriding work around
"Benno Luthiger" <[email protected]>
| Newsgroups | gmane.comp.web.zope.silva.devel |
|---|---|
| Message-ID | <000601c52af8$d8ed8d30$1e238481@openlu> |
Dear Silva developers,
With silva/index_html Silva offers the opportunity to override the standard
layout with a local layout. This is a nice feature and useful for some
abvious website designs. The override mechanisme works fine if the container
(e.g. Silva Folder or Publication) containing the override template is
called. However, it fails if the container's default document 'index' is
called explicitely. And of course it fails in our situation where we
implemented multilingual support by simply postfixing the language key to
the document. Instead of displaying the content of 'mysite/index_DE' in the
override layout, the content is rendered with the default layout.
To overcome this problem I've modefied the Script 'index_html' slightly by
checking the context.id and installed this modified version somewhere beyond
the Silva Root:
_______________________________________________________________________
## Script (Python) "index_html"
##parameters=view_method='view'
content = 'content.html'
override = 'override.html'
#Here's my overriding work around
if context.id in ['index', 'index_DE', 'index_EN']:
aq_context = context.get_container().aq_explicit
else:
aq_context = context.aq_explicit
# By default, the rendering is done by 'content', unless
# a local 'override' exists (disregarding acquisition).
if hasattr(aq_context, override):
renderer = override
else:
renderer = content
# Setting Headers first
context.REQUEST.RESPONSE.setHeader('Content-Type',
'text/html;charset=utf-8')
context.REQUEST.RESPONSE.setHeader('Cache-Control','max-age=300')
# By default, the prefered view method is 'view()', unless
# a different view_method is passed to this script.
return getattr(context, renderer)(view_method=view_method)
_______________________________________________________________________
Do you see a draw back with this work around?
Regards,
Benno Luthiger
_______________________________________________________________________
Benno Luthiger
WEP J 11
Swiss Federal Institute of Technology Zurich
CH-8092 Zurich
Tel: +41 1 632 57 65
_______________________________________________________________________