Search code examples
javascriptsmarty

Importing template file in JavaScript by using smarty


Hi guys i want to import my script template with JavaScript by using smarty but this my code not work and i have an error can some one tell my how i can do that in true way? Thank you.

JS:

var tpl = {include file="myscript.tpl"};
$('.plus').html(tpl);

ERROR:

Uncaught SyntaxError: Unexpected identifier in

var tpl = {include file="myscript.tpl"};

Solution

  • Your Javascript is probably within literal tag, so what you need to do is:

    {literal}
    <script>
    ....
    var tpl = '{/literal}{include file="myscript.tpl"}{literal}'; /* it will be a string */
    ....
    </script>
    {/literal}
    

    This topic may also help you.