how to add a script tag inside a jquery template.

You cannot directly add a script tag inside a jquery template.

suppose you want to add a script tag inside a jquery template in the following way:

<script id="filaVideoTemplate" type="text/x-jQuery-tmpl">
<!-- Some HTML here -->
<script type="text/javascript">
<!-- Some javascript here -->
</script>
</script>

This will not work.Because browsers don’t understand nesting of tags, so whenever it parses a , it closes the outermost script tag.

You should write  ” </scr{{= “”}}ipt>  “instead of closing the inside script directly as  ” </script> “.

so that the code look like:

<script id="filaVideoTemplate" type="text/x-jQuery-tmpl">
<!-- Some HTML here -->
<script type="text/javascript">
<!-- Some javascript here -->
{{html "</sc"+"ript>"}}
</script>

so this is the solution.

Further for the django developers, this is not the solution.
because ‘{‘ and ‘}’ are reserved characters in django templates. so instead of writing
{{html “</sc”+”ript>”}}
we have to write:
{% templatetag openbrace %}{% templatetag openbrace %}html “</sc”+”ript>”}{% templatetag closebrace %}{% templatetag closebrace %}

This will work for django templates.

Advertisements