[ZPT] Moving scripts to center stage

Evan Simpson evan@digicool.com
Thu, 31 May 2001 16:15:17 -0500


From: "Wade Leftwich" <wade@lightlink.com>
> Right now, when I call a script at the top of my template, I say:
> <span tal:define="global pagedict container/myscript"/>. Pagedict
might look
> like this:
> {'title':'This Just In', 'Dateline':<DateTime instance at 12345>,
> 'tblrow':<r instance at cd6345789>}
>
> What I'm hunting for is a simple way to call the template from the
script.

> return container.newtemplate(container.newtemplate, req)

Ah, you need to know about PT call signatures.  Page Templates aren't
like DTML; It is neither required nor useful to pass the client and
request.  All keyword arguments in the call are collected as a
dictionary in a variable called 'options'.  If there are positional
arguments, they are placed (as a list) in 'options/args'.

So, you could use:


return container.newtemplate(pagedict=pagedict)

tal:define="global pagedict options/pagedict | here/pagedict"

> P.S. ZPT's have "here" and Python scripts have "context". They seem
like
> they're much of a muchness, despite the different names. Is that true?

They're exactly the same, yes.

Cheers,

Evan @ digicool