Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ending haml comments

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.

like image 969
thinkfuture Avatar asked Jun 10 '11 18:06

thinkfuture


People also ask

How do you comment Haml code?

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 Haml in CSS?

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.

How does Haml work?

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.


1 Answers

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.

like image 102
D. Simpson Avatar answered Oct 17 '22 20:10

D. Simpson