[ZPT] Acquiring PT local context (e.g. state of defines, repeat) within python scripts?
Jeff Kowalczyk
jtk@yahoo.com
Thu, 26 Dec 2002 15:30:19 -0500
I'm making every effort to keep logic out of the Page Templates I'm writing, creating many
python scripts in the process. The parameter lists to some of the scripts called with
python:here.myScript() get pretty long and complex.
I'd like to try acquisition in the python scripts to get at the Page Template execution
'context', such as the current tal:defined variables, the current state of the
batch/repeats, etc., without making an enormous parameter lists. Something like the
following pseudocode (which fails with an attribute error, obviously):
<html><body>
<p tal:define="mystring string:yada">This is the result of the call to script1.<br>
<pre tal:content="here/script1">Script Results</pre></p>
</body></html>
request = container.REQUEST
RESPONSE = request.RESPONSE
print 'context.mystring:', context.mystring
return printed
I think it could be useful and productive if I coded fairly defensively in the python
scripts to gaurd against acquisition misses.
Can I bind to something in a python script that gives me access to the current PT
environment as described?
If it is a common technique, would anyone have a link to somewhere I could read up on this
specific technique of using scripts with page templates? Thanks.