简体   繁体   中英

smarty error seen in JS code

I am trying to use tiny mce (JS editor ) in a web page rendered by Smarty 3. But when I use the below code , It throws the following error

The specific message was: Syntax Error in template "/home/xxx/xxx/websites/site.local/views/xxx/newnl.html.tpl" on line 564 "m.add({title : "Subject {test}", onclick : function() {" - Unexpected " : ", expected one of: "}" , " "

Code :

<script language="javascript" type="text/javascript" src="http://127.0.0.1/./js/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">

tinymce.create("tinymce.plugins.yyyPlugin", {
    createControl: function(n, cm) {
        switch (n) {
            case "tm_menubutton":
            var c = cm.createMenuButton("tm_menubutton", {
                title : "yyy",
                image : "http://127.0.0.1/./img/yyy_logo.png",
                icons : false
            });
            c.onRenderMenu.add(function(c, m) {
                m.add({title : "Subject {test}", onclick : function() {
                    tinyMCE.activeEditor.execCommand("mceInsertContent", false, "{test}");
                }});

 });
}
}
});
</script>

Could anyone have a look at it ? Thanks

You should enclose your JS code using the {literal}{/literal} tag if you haven't. This prevents Smarty from parsing what's in between so that the JS code is not being mistaken for PHP code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM