[Zope] ZPT changing javascript (HOW?) - Easy with DTML

Martijn Pieters mj@zope.com
Thu, 3 Oct 2002 17:19:25 -0400


On Thu, Oct 03, 2002 at 02:46:54PM -0500, Christopher N. Deckard wrote:
> <script tal:define="USER_NAME user/getUserName"
>         type="text/javascript">  
> function connect()
>   {
>     username = <span tal:replace="USER_NAME">username</span>;
>   }
> </script>
> 
> </body>
> </html>

Don't use tags within the script tag, the HTML spec specifically forbids
that. I use the following construct for transferring Zope data into
javascript variables, this is a real life example:

<script type="text/javascript" tal:content="structure string:
    portalURL = &quot;${here/portal_url}&quot;
    editionURL = &quot;${here/absolute_url}&quot;
" />
<script type="text/javascript">
// Your code goes here
</script>

The first script tag has its contents dictated by the tal:content attribute.
The second script tag has access to whatever you define in the context of
the first, including the Zope data we just stuffed into there.

Translating this to your specific case is left as an exercise. ;)

-- 
Martijn Pieters
| Software Engineer  mailto:mj@zope.com
| Zope Corporation   http://www.zope.com/
| Creators of Zope   http://www.zope.org/
---------------------------------------------