I am new to haml and this is stumping me. I don't like to delete code where I can comment it out but I have no idea how to properly end a comment in haml.
Here is a code snippit:
.field
= f.label :member_id
%br/
= f.text_field :member_id
.field
= f.label :instrument_type
%br/
I'm trying to comment out the first field so I used:
/
.field
= f.label :member_id
%br/
= f.text_field :member_id
.field
= f.label :instrument_type
%br/
but that commented out everything after the first field.
Then I tried:
/
.field
= f.label :member_id
%br/
= f.text_field :member_id
.field
= f.label :instrument_type
%br/
but it didn't like that either, or:
-#.field
-# = f.label :member_id
-# %br/
-# = f.text_field :member_id
.field
= f.label :instrument_type
%br/
I must be missing something. I looked all over but the examples never show code after the comment.
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.
What is it? Haml (HTML abstraction markup language) is based on one primary principle: markup should be beautiful. It's not just beauty for beauty's sake either; Haml accelerates and simplifies template creation down to veritable haiku.
In Haml, we write a tag by using the percent sign and then the name of the tag. This works for %strong , %div , %body , %html ; any tag you want. Then, after the name of the tag is = , which tells Haml to evaluate Ruby code to the right and then print out the return value as the contents of the tag.
It's your spacing that is causing the problem, not your method. Here is the proper way to comment out those lines in HAML:
Your 4th example is really close:
-#.field
-# = f.label :member_id
-# %br/
-# = f.text_field :member_id
.field
= f.label :instrument_type
%br/
Commented out properly:
-#.field
-# = f.label :member_id
-# %br
-# = f.text_field :member_id
.field
= f.label :instrument_type
%br
This is awfully close to what you posted on your last example, with a notable exception: Your comment lines begin with a space preceding the -#
. That space at the beginning will break HAML. I also noticed that your source code is indenting by one space instead of two. This will also break HAML. It must be two spaces of indentation.
P.S. You can remove the trailing slash from your %br
lines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With