2

有没有办法将注释(单行和多行)放在ECO 模板中,这样它们就不会出现在呈现的输出中?

例如,Django 模板允许您在一行中执行此操作:

{# greeting #}hello

或多

<p>Rendered text with {{ pub_date|date:"c" }}</p>
{% comment %}
    <p>Commented out text with {{ create_date|date:"c" }}</p>
{% endcomment %}
4

2 回答 2

3

实际上里面的所有东西<% %>都是咖啡脚本(ECO = Embedded CoffeeScript)。CoffeeScript 中的注释使用#字符来注释单行(以及###多行注释)。见coffeescript - 如何评论?“/* 这个 */” 不起作用

所以在 ECO 你会这样评论:

<% #This is a single line comment %>

如果您检查ECO 模板的源代码,您可以看到在scanner.js 中处理注释情况的正则表达式

Scanner.modePatterns = {
      data: /(.*?)(<%%|<%\s*(\#)|<%(([=-])?)|\n|$)/,
      code: /(.*?)((((:|(->|=>))\s*))?%>|\n|$)/,
      comment: /(.*?)(%>|\n|$)/
    };
于 2014-05-15T09:40:31.750 回答
2

有一个特殊的评论标签,即<%# %>

例子:

<%# This is a single line comment %>
于 2017-07-05T08:22:26.157 回答