Accessing Zope variables with Javascript
written by Ian McCracken
at Monday, March 24, 2008
ZPT totally ignores the contents of
I generally have one of these up at the top of the template, storing
<script>
tags, which makes it kind of a hassle to use values from the server in your Javascript. Short of writing a whole integration framework, the best way I've found to pull variables from page templates into Javascript is like this:<tal:block tal:define="foo accessor/for/myvar">
<script tal:content="string:
var foo='${foo}';
"></script>
</tal:block>
I generally have one of these up at the top of the template, storing
portal_url
and whatever else I might need in a namespaced array. You can run into problems with nested quotes, but if you don't have the time to write more complex back-end methods, it's a handy quick-and-dirty hack.