嵌入式Coffeescript(ECO)模板中的注释

时间:2014-02-27 23:07:49

标签: coffeescript eco

有没有办法在ECO templates中放置注释(单行和多行),使它们不会出现在渲染输出中?

例如,Django模板允许您在single line上执行此操作:

{# greeting #}hello

multiple lines

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

2 个答案:

答案 0 :(得分:3)

有效地,<% %>内的所有内容都是coffeescript(ECO = Embedded 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|$)/
    };

答案 1 :(得分:2)

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

示例:

<%# This is a single line comment %>
相关问题