dosuken123 dosuken123 - 4 months ago 8
Ruby Question

Comment out an item in table on haml

You have a table on haml.

%table
%tr
%th HOGE1
%th HOGE2
%tr
%td HAGE1
%td HAGE2


Now you want to comment out the first item.

%table
%tr
-# %th HOGE1
%th HOGE2
%tr
-# %td HAGE1
%td HAGE2


...

WHY IT DOESN'T WORK.....?

Answer

There should not be spaces between -# and %th try:

%table
  %tr
    -#%th HOGE1
    %th HOGE2
  %tr
    -#%td HAGE1
    %td HAGE2

Output html:

<table>
  <tr>
    <th>HOGE2</th>
  </tr>
  <tr>
    <td>HAGE2</td>
  </tr>
</table>

#- will omit corresponding line. / will comment out the line and generate html comment

%table
  %tr
    /%th HOGE1
    %th HOGE2
  %tr
    / %td HAGE1
    %td HAGE2

Output html : <table> <tr> <!-- %th HOGE1 --> <th>HOGE2</th> </tr> <tr> <!-- %td HAGE1 --> <td>HAGE2</td> </tr> </table>