PHP混淆了<;?php<;%下划线模板


PHP mixing up <?php <% underscore template

我在一个wordpress插件中使用underscorejs模板系统,但其中一个用户给我发了这样的消息:

分析错误:语法错误,/wp-content/plugins/dnui中的意外T_VAR删除未使用第13行上的image wordpress/html/backup.php

经过一些搜索,我得出结论,php正在像<?php一样解释<%,并试图运行代码,但代码在js/template下划线中

<% var src; %>

你们有人知道为什么会这样吗?如何修复?我尝试搜索如何更改

<?php

对于另一种类型,但只得到的答案

<? 

如果您使用wp.template作为模板,您可以在这里找到答案

如果你直接在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 ) );