quick search:
 

index_html and acquistion to increase default views

Submitted by: runyaga
Last Edited: 2007-01-29

Category: DTML

Average rating is: 2.0 out of 5 (1 ratings)

Description:
the default view of a folder is index_html. most of your webpages if
moving to ZOPE probably follow the index.html or index.htm naming convention.
instead of renaming all your default files index_html, we create a
DTML Method and (Script) Python once and use it throughout the system
via Acquisition.

in the root folder create a DTML Method to render the object and use a Python Script
to get the object efficiently (also avoids messing DTML).



Source (Text):
DTML Method, index_html::
<dtml-call "REQUEST.set('default', getDefaultFile)">
<dtml-var expr="_.getitem(_['default'], 1)">

(Script) Python, getDefaultFile::
defaultFiles=['index.htm', 'index.html', 'index.php', 'index.php3', 'default.asp', 'home.jsp']
for default in defaultFiles:
    if hasattr(context, default): return getattr(context, default).getId()

Explanation:
the DTML Method calls the Python Script which checks the current
directory for each default in the defaultFiles list. the first one
it finds it returns the id attribute (i.e. index.php)

the DTML Method then sets the returned id to a variable called default and
then uses the dtml utility getitem to render it.

Resource: DMTL Namespace Utilities - http://www.zope.org/Members/michel/ZB/AdvDTML.dtml

USE: create both DTML Method and (Script) Python in the root directory, cut-n-paste the code
create a folder called 'test'
create a dtml document called index.php
in the url goto test/ and you should see index.php being displayed


Comments:

No Comments