Hello, searching the web for the subject keywords I found: http://www.zopelabs.com/cookbook/1024946669 If I try this example: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "DTD/xhtml1-strict.dtd"> <html> <head> <title tal:content="template/title">Influenza</title> <link rel="stylesheet" type="text/css" href="influenza.css"> </head> <body metal:define-slot="body" tal:define="global session here/session_data; global pss modules/Products/PythonScripts/standard"> ... --> Errors Compilation failed TAL.TALDefs.METALError: define-slot must be within a define-macro, at line 7, column 1 Any hint how to do this right or any other possibility to foreward a variable to a page template by a python script? My intend was something like this: session=context.REQUEST.SESSION session['var'] = 'variable' if REQUEST is not None: return container['test.html'](REQUEST) But may be I could foreward var in any other way and this I would not neet the SESSIOn variable. Kind regards Andreas.
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.
On Fri, 27 Sep 2002, Julian Melville wrote:
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> Many thanks!
This should be documented in Zope Book or anywhere else were it is easy to find! Kind regards Andreas.
On Fri, 27 Sep 2002, Julian Melville wrote:
<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> Thanks this works so far. But I want to foreward one of the parameters to a further script inside the page template like this:
<span tal:replace="structure python:here.Script(options/xxx)">xxx</span> but neigther this nor <span tal:replace="structure python:here.Script(xxx)">xxx</span> works. Any hint here? Kind regards Andreas.
Thanks this works so far. But I want to foreward one of the parameters to a further script inside the page template like this:
<span tal:replace="structure python:here.Script(options/xxx)">xxx</span>
but neigther this nor
<span tal:replace="structure python:here.Script(xxx)">xxx</span>
works. Any hint here?
No problems... remember that you're speaking Python syntax inside those calls, so you can either refer to the xxx variable directly as options['xxx'], or you can use tal:define to make a local copy of the variable within the ZPT. That's a better solution if you're going to use your xxx variable in several places: <span tal:replace="structure python:here.Script(options['xxx'])">xxx</span> or <span tal:define="xxx options/xxx" tal:replace="structure python:here.Script(xxx)">xxx</span> Cheers, Julian (gone for a beer or two... it's Friday night in Australia)
participants (2)
-
Andreas Tille -
Julian Melville