Search code examples
ruby-on-railscoffeescriptcommentshamlhamlc

How to comment out a line in HAMLC comment


Wondering how to comment out one line in HAMLC. I Tried

# this is commented out

But it doesn't work. It creates a <div> this is commented out </div> Can't find many resources on HAMLC.

Knowing how to comment out multi-line would also be appreciated.


Solution

  • This is from the Haml documentation for comments:

    Comments

    Haml supports two sorts of comments: those that show up in the HTML output and those that don’t.

    HTML Comments: /

    The forward slash character, when placed at the beginning of a line, wraps all text after it in an HTML comment. For example:

    %peanutbutterjelly
      / This is the peanutbutterjelly element
      I like sandwiches!
    

    is compiled to:

    <peanutbutterjelly>
      <!-- This is the peanutbutterjelly element -->
      I like sandwiches!
    </peanutbutterjelly>
    

    The forward slash can also wrap indented sections of code. For example:

    /
      %p This doesn't render...
      %div
        %h1 Because it's commented out!
    

    is compiled to:

    <!--
      <p>This doesn't render...</p>
      <div>
        <h1>Because it's commented out!</h1>
      </div>
    -->
    

    Conditional Comments: /[]

    You can also use Internet Explorer conditional comments by enclosing the condition in square brackets after the /. For example:

    /[if IE]
      %a{ :href => 'http://www.mozilla.com/en-US/firefox/' }
        %h1 Get Firefox
    

    is compiled to:

    <!--[if IE]>
      <a href='http://www.mozilla.com/en-US/firefox/'>
        <h1>Get Firefox</h1>
      </a>
    <![endif]-->
    

    Haml Comments: -#

    The hyphen followed immediately by the pound sign signifies a silent comment. Any text following this isn’t rendered in the resulting document at all.

    For example:

    %p foo
    -# This is a comment
    %p bar
    

    is compiled to:

    <p>foo</p>
    <p>bar</p>
    

    You can also nest text beneath a silent comment. None of this text will be rendered. For example:

    %p foo
    -#
      This won't be displayed
        Nor will this
                       Nor will this.
    %p bar
    

    is compiled to:

    <p>foo</p>
    <p>bar</p>
    

    These are other references: