2014-10-27 66 views
2

我用underscorejs模板系统在我的WordPress插件之一,但用户的一个给我这个消息:PHP混淆<PHP <%下划线模板

Parse error: syntax error, unexpected T_VAR in /wp-content/plugins/dnui-delete-not-used-image-wordpress/html/backup.php on line 13

做一些搜索后,我来到了的结论是,PHP是解释<%<?php,并试图运行代码,但是代码在JS /模板强调

<% var src; %> 

您有任何的为什么是这样的任何想法?如何解决它?我试图寻找如何改变

<?php 

另一种类型,但只得到了

<? 
+3

禁用此功能:http://php.net/manual/en/ini.core.php#ini.asp-tags – 2014-10-27 12:55:49

+0

你是什么意思“php正在使用<%like”?就像它将'<?php'转换为'<%',或者默认使用asp标签?另外'var src;'看起来不像有效的PHP,是underscorejs的一部分吗? – 2014-10-27 12:56:08

+0

感谢@SergiuParaschiv我试图找到PHP文档在这个信息,但看到了,我没有做一个很好的搜索。 – nicearma 2014-10-27 13:00:11

回答

0

答案如果您使用您的模板wp.template你可以找到你的答案here

如果您可以直接在JS使用下划线的模板文件,你应该改变模板设置是这样的:

/* 
    * Underscore's default ERB-style templates are incompatible with PHP 
    * when asp_tags is enabled, so your template uses Mustache-inspired templating syntax. 
    * 
    * Make the underscore template like wp.template function 
    * 
    */ 
    var templateSettings = { 
     evaluate : /<#([\s\S]+?)#>/g, 
     interpolate : /\{\{\{([\s\S]+?)\}\}\}/g, 
     escape  : /\{\{([^\}]+?)\}\}(?!\})/g, 
     variable : 'data' 
    }; 

    var innerGizmoTemplate = '<div class="{{ data.className }}">' 
    + ' <# _.each(data.params, function(param){ #>' 
    + ' <div class="karma-builder-gizmo-{{ param.type }} {{ param.className }} ">' 
    + ' <# if("icon" === param.type){ #>' 
    + ' <div>{{{ param.icon }}}</div>' 
    + '<# } else if("text" === param.type) {#>' 
    + '<div>{{{ param.value }}}</div>' 
    + '<# } #>' 
    + '</div>' 
    + '<# }) #>' 
    + '</div>' ; 

// then get it easily like this 
var compiled = _.template(innerGizmoTemplate, templateSettings); 
console.log(compiled(YourParams));