2

Is there a way to put comments (single and multiline) in ECO templates such that they do not appear in the rendered output?

For example, Django templates let you do this on a single line:

{# greeting #}hello

or on multiple lines:

<p>Rendered text with {{ pub_date|date:"c" }}</p>
{% comment %}
    <p>Commented out text with {{ create_date|date:"c" }}</p>
{% endcomment %}
Erik
  • 7,479
  • 8
  • 62
  • 99

2 Answers2

3

Effectively everything inside the <% %> is coffeescript (ECO = Embedded CoffeeScript). Comments in CoffeeScript use the # character to comment a single line (and ### for multiline comments). See coffeescript - How to comment? "/* this */" doesn't work

So in ECO you would comment like this:

<% #This is a single line comment %>

If you examine the source code for ECO templates you can see the regex that's handling the comment situation in scanner.js.

Scanner.modePatterns = {
      data: /(.*?)(<%%|<%\s*(\#)|<%(([=-])?)|\n|$)/,
      code: /(.*?)((((:|(->|=>))\s*))?%>|\n|$)/,
      comment: /(.*?)(%>|\n|$)/
    };
Community
  • 1
  • 1
Steve Mc
  • 3,433
  • 26
  • 35
2

There is a special tag for commenting, namely, <%# %>

Example:

<%# This is a single line comment %>
Cristiano Mendonça
  • 1,220
  • 1
  • 10
  • 21