Context sensitive index_html
Created by .
Last modified on 2003/08/05.
One idiom that is quite often used in Zope acquiring methods,
especially index_html.
/ Folder
/index_html DTML Method
/dataitem0 Kube
/dataitem1 Kube
The dataitems do not provide their own index_html,
so they acquire the /index_html method.
Now this works quite well, with one exception:
/ now lacks it's own index_html.
Depending upon what implementation language was
choosen for /index_html generating a special case
can be easy or difficult.
Basically we'd like to implement the dataitem index_html
with Page Templates and the / Folder index with
DTML. (generating a list view is easy enough
in DTML).
This is not as difficult as it sounds:
Generate a python Script index_html like this:
request = container.REQUEST
name="index_html_"+context.meta_type
if hasattr(context,name):
return getattr(context,name)(context,request)
else:
return getattr(context,"index_html_default")
Afterwards create a /index_html_Kube and
/index_html_Folder in /.
When / is accessed /index_html dispatches to
/index_html_Folder. When /dataitem0 is viewed,
/index_html_Kube will be accessed.
Andreas
|