smarty error seen in JS code

匆匆过客 提交于 2019-12-25 06:51:05

问题


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


回答1:


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.



来源:https://stackoverflow.com/questions/5429012/smarty-error-seen-in-js-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!