[Zope] ZPT and SESSION variable

Julian Melville jmelville@selectaustralasia.com.au
Fri, 27 Sep 2002 15:11:41 +1000


> Any hint how to do this right or any other possibility to
> foreward a variable
> to a page template by a python script?

To send variables into a ZPT from a Python script, just call the ZPT as if
it were a Python function and just pass the variables in by name. This is my
favourite thing about ZPT's, that they're so easy and elegant to call from
scripts. It makes it really easy to have all your logic in a few lines of
python, and then return a page once you're done.

In a python script:

 xxx = 3
 yyy = ['list', 'of', 'stuff']
 return container['test.html'](xxx=xxx, yyy=yyy)


Inside the ZPT, the request is already available as the variable 'request'
and the variables you pass in come in underneath a variable called
'options':

  <span tal:replace="options/xxx">dummy content</span>

will show up in your page as just the number 3.

 <div tal:repeat="item options/yyy" tal:content="item">dummy content</div>

will give you

 <div>list</div>
 <div>of</div>
 <div>stuff</div>


The ZPT articles here: http://www.zope.org/Documentation/Articles will fill
in the other details for you.

Julian.