<script> tag inside jquery template <script> tag inside jquery template ajax ajax

<script> tag inside jquery template


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

You can use {{html "</sc"+"ript>"}} replace </script>


Not sure if this is the only way, but you can insert the script as raw HTML for the template:

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

Then:

var innerScript = '<script type="text/javascript"><!-- Some javascript here --></script>';$('#filaVideoTemplate').tmpl({innerScript: innerScript});


Ronny Wang's answer offered a good place to start for my problem. However, his solution didn't work for me -- the .. tags in the body of the jQuery template was causing problems on my MVC3 Razor view page.

Fortunately, I stumbled across a solution ( details @ https://github.com/jquery/jquery-tmpl/issues/94 ) that works and requires only a minor change. Here's Ronny's answer, but with a fix that should make it MVC3-compatible:

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

Looks like both the opening and closing tag just need to be broken up. Hope this helps!