[Zope] Var Includes:Extension

shawh@sths.org shawh@sths.org
Wed, 24 Feb 1999 12:27:26 -0600


Well, I gave up on a DTML only method, and wrangled with Extensions till I got
it right: Here's the code, in case anyone's interested.

from string import split

def getbypath(ob, path):
        """Return an object as directed by 'path'"""
        parent=None
        current=ob
        for i in split(path, "/"):
                try:
                        parent=current
                        current=getattr(current,i)
                except TypeError:
                        return "Encountered Exception"
        parent.temp_child=i              
        return parent

And here's the DTML that calls it:

<!--#var standard_html_header-->
<!--#with expr="getbypath(ob=PARENTS[0],path='index_html')"-->
 <!--#var "_[temp_child]"-->
<!--#/with-->
<!--#var standard_html_footer-->

Of course the real DTML would have some variable in place of 'index_html'!
note: the simplest and most obvious course (to me) gave poor results. If the
Extension method returns 'current' then you get the equivelant of a '#var ...
urlquote' where not even the DTML is evaluated. The mucking about with 'parent'
and 'temp_child' is necessary to bring it in properly pre-evaluated. But now it
works fine.

Thanks to all who helped.