Skip to content

Comments

Template::HAML supports three forms of comments: HTML comments, conditional comments, and silent comments.

HTML comments — /

A line beginning with / is rendered as an HTML comment.

Single-line form:

1
/ Hello
1
<!-- Hello -->

If the / line has children indented underneath, they are rendered inside the comment block:

1
2
/
  %p hi
1
2
3
<!--
  <p>hi</p>
-->

Conditional comments — /[expr]

Use /[expr] to emit a conditional comment. The bracketed text becomes the condition; surrounding whitespace is stripped.

Inline form:

1
/[if IE] text
1
<!--[if IE]>text<![endif]-->

Block form:

1
2
/[if IE]
  %p ie only
1
2
3
<!--[if IE]>
  <p>ie only</p>
<![endif]-->

Negated:

1
/[if !IE] text
1
<!--[if !IE]>text<![endif]-->

Revealed conditional comments — /![expr]

Prefix the bracket with ! to emit a downlevel-revealed conditional comment. Browsers that don't honor the condition see the wrapped content as plain markup:

1
/![if !IE] text
1
<!--[if !IE]><!-->text<!--<![endif]-->

Silent comments — -#

A line beginning with -# is suppressed entirely. Any indented body — including any number of blank lines — is treated as opaque text and produces no output:

1
2
3
4
5
%p hi
-# notes:
   arbitrary text $^&* not parsed as HAML
   !!! also opaque
%p bye
1
2
<p>hi</p>
<p>bye</p>

Because the body is opaque, you can drop in non-HAML content (e.g. design notes, stale code, scratch markup) without provoking parse errors.