开发者

How to correctly include javascript code in chameleon/zpt template (pyramid)?

开发者 https://www.devze.com 2023-02-14 07:18 出处:网络
I\'m trying to embed some code between <script> </script> tags, pyramid however doesn\'t like it and gives me

I'm trying to embed some code between <script> </script> tags, pyramid however doesn't like it and gives me

ExpatError: n开发者_StackOverflow中文版ot well-formed (invalid token)

Probably because i have && in my code. I tried using &amp; instead, but then it didn't get interpreted in the browser.

The same thing happens when i try to put it in CDATA block.

When I move the code to a separate js file it works. I'd like to keep it in the same file for now, just to enable quick corrections.

So, how should I do it?

EDIT:

I get the same error even for templates as simple as this one:

<html
    xmlns:tal="http://xml.zope.org/namespaces/tal"
    xmlns:metal="http://xml.zope.org/namespaces/metal">
    <head>
    </head>
    <body>
        <span onclick="alert(true && false);">test</span>
    </body>
 </html>


I think you're supposed to put && (i.e. two times the HTML entity code).


This should work:

<script type="text/javascript">
    //<![CDATA[
        // my javascript
    //]]>
</script>


Have you tried adding a type attribute to your script tag?:

<script type="text/javascript">
...
</script>


It looks like xhtml issue, as w3c validator reported the same error.

I was thinking if there's a switch to change the document type parsed by chameleon to html, but then it wouldn't be possible to include tal and metal namespaces.

Hence it is expected behavior

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号