有没有办法在 ECO templates 中添加注释(单行和多行)这样它们就不会出现在渲染的输出中?
例如,Django 模板允许您在 single line 上执行此操作:
{# greeting #}hello
<p>Rendered text with {{ pub_date|date:"c" }}</p>
{% comment %}
<p>Commented out text with {{ create_date|date:"c" }}</p>
{% endcomment %}
最佳答案
实际上 <% %>
内的所有内容是 CoffeeScript(ECO = 嵌入式 CoffeeScript)。 CoffeeScript 中的注释使用 #
用于注释单行的字符(###
用于多行注释)。请参阅coffeescript - How to comment? "/* this */" doesn't work
所以在 ECO 中你会这样评论:
<% #This is a single line comment %>
如果您检查 ECO templates 的源代码您可以在 scanner.js 中看到处理评论情况的正则表达式.
Scanner.modePatterns = {
data: /(.*?)(<%%|<%\s*(\#)|<%(([=-])?)|\n|$)/,
code: /(.*?)((((:|(->|=>))\s*))?%>|\n|$)/,
comment: /(.*?)(%>|\n|$)/
};
关于coffeescript - 嵌入式 Coffeescript (ECO) 模板中的注释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22082656/