jQuery或underline.js模板导致XML解析器错误

jQuery或underline.js模板导致XML解析器错误,xml,parsing,underscore.js,thymeleaf,underscore.js-templating,Xml,Parsing,Underscore.js,Thymeleaf,Underscore.js Templating,我的HTML文件中有下划线或jQuery模板。有点像: <script type="text/template" id="myId"> <h1><%=catalog.title %></h2> <div class="action"> <% if(isGood) { %> we are good <% } else { %>

我的HTML文件中有下划线或jQuery模板。有点像:

<script type="text/template" id="myId">
    <h1><%=catalog.title %></h2>
    <div class="action">
         <% if(isGood) { %>
           we are good
       <% } else { %>
           we are not good
       <% } %>
    </div>
</script>

我们很好
我们不好
如果我把它放在一个.jsp文件或.vm文件中,这是非常好的


但是如果使用ThymeLeaf,那么我将有一个解析问题。我猜这是由thymeleafxml解析器引起的。它不允许类似“的内容为了避免Thymeleaf解析器异常,您可能希望根据将ERB样式分隔符更改为Mustache.js样式(或任何其他样式),只需在任何其他与下划线.js相关的代码之前插入以下JavaScript代码:

_.templateSettings = {
    interpolate: /\{\{(.+?)\}\}/g
};
例:代替

<h1><%=catalog.title %></h2>

你会写信吗

<h1>{{ catalog.title }}</h2>
{{catalog.title}

我在使用handlebar.js模板(使用{{foo}}表示法)时遇到了同样的问题。对于我来说,将Thymeleaf设置为有效(遵循给出的建议)。我还必须将nekohtml添加到类路径中。

经过几周的徒劳之后,我终于能够在Thymeleaf XHTML模式的范围内呈现下划线模板,这是在我无意中遇到的。所有CDATA和Thymeleaf标记的排列都失败了,直到我在CDATA标记后插入了额外的随机注释,例如:

<script type="text/template" id="my-template">
    <![CDATA[
    <!-- guard comment to prevent browsers from considering the previous and next lines as part of a comment -->
    <tr>
        <td><%- myParam%></td>
    </tr>
    <!-- ]]> -->
</script>