[ZPT] Moving scripts to center stage
Wade Leftwich
wade@lightlink.com
Thu, 31 May 2001 15:43:57 -0400
Now that I've been working with Page Templates for a whole two weeks, I find
myself constantly using the pattern that Evan and others have described: at
the top of the template, call a script to load up all the data structures,
then use TAL strictly for presentation logic.
Now I've got a situation where I'd like to put the script in the URL and
have it decide which template to use. For example, with these two Urls:
myzope.com/article/42.html
myzope.com/article/42.xml
. . . I want the Python script named 'article' to look in its
traverse_subpath. It will pull record 42 from someplace (maybe a ZSQL
method). If the extension is 'html', it will use the template 'article_html'
for display; if 'xml', 'article_xml'. You can see how the idea could be
extended to make appropriate responses based on browser capabilities, or
type of platform (wireless etc).
With a hint from Steve Drees (thanks Steve!) I got the subpath part working,
and a search of the zope mailing list archives found good info on how to
call a DTML method from a script -- much of the good explanation came from
Evan. (Thanks Evan!) So now I know how to set a variable in REQUEST and pass
it to a template.
Here's my question. Is there a straightforward way to add an object to the
template's 'here' when I call it? That way the template could work the same
way whether it was called from a script or via a Url. If not, maybe the best
way to do this is with some logic at the top of the template, that looks for
an object named 'pagedict', first in REQUEST, then in 'here', and finally by
calling a script. Or maybe templates do something like that already, and I
haven't noticed it yet?
Finally -- a big thankyou to the ZPT Folks for facilitating my big Zope
breakthrough. (Thanks also for Python Scripts.) DTML always seemed somewhat
icky, and made Zope hard to sell to Microsoft-oriented clients and
employers. With ZPT and Scripts, everything makes sense.
Wade Leftwich
Ithaca, NY