RE: [Zope] RE: Dynamically generating JavaScript
Yes, you are right that works fine and is cleaner. My point is that Zope does not seem to render tal statements between <script> tags. They get ignored. This works <script type="text/javascript" tal:content="here/myscript_js"></script> but this does not. <script type="text/javascript" > <tal:block tal:content="here/myscript_js" /> </script> Andy
-----Original Message----- From: zope-bounces@zope.org [mailto:zope-bounces@zope.org] On Behalf Of Duncan Booth Sent: Monday, February 14, 2005 9:04 AM To: zope@zope.org Subject: [Zope] RE: Dynamically generating JavaScript
Andy Yates wrote:
When I've had to include dynamic javascript I write a python method that prints the whole script block and then call that from a tal:block.
<tal:block tal:replace="structure python: here.myscript_js()" />
myscript_js would look like this
print """<script> var1 = 1; var2 = 2; var3 = 3; </script>"""
return printed
Wouldn't it make more sense to do:
<script type="text/javascript" tal:content="here/myscript_js"></script>
and just have myscript_js print the Javascript without the enclosing script tags?
for i in range(1,4): print "var%d = %d" % (i, i)
return printed
Or even better, if your script contents don't depend on values from the current request use:
<script type="text/javascript" src="myscript_js"></script>
which keeps the Javascript entirely outside the html so you don't have to worry about embedded angle brackets.
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Am Montag, den 14.02.2005, 10:37 -0600 schrieb Andy Yates:
Yes, you are right that works fine and is cleaner. My point is that Zope does not seem to render tal statements between <script> tags. They get ignored.
This works <script type="text/javascript" tal:content="here/myscript_js"></script>
but this does not.
<script type="text/javascript" > <tal:block tal:content="here/myscript_js" /> </script>
This is a known FAQ and in short its not a property of TAL but of HTML. The declaration does not allow for tags inside <script /> HTH Tino
participants (2)
-
Andy Yates -
Tino Wildenhain