Skip to content

Indentation

HAML uses indentation to express nesting. A line that's indented further than the previous line becomes a child of that line; a line at the same indent is a sibling; a line at a shallower indent closes one or more parents.

Two-space indent

Template::HAML currently expects two-space indentation:

1
2
3
4
5
%section.container
  %h1 Title
  %ul
    %li Foo
    %li Bar
1
2
3
4
5
6
7
<section class='container'>
  <h1>Title</h1>
  <ul>
    <li>Foo</li>
    <li>Bar</li>
  </ul>
</section>

Inconsistent indentation is rejected

An odd-spaced indent is rejected with X::IllegalIndent:

1
2
%section
   %h1 Title
1
Illegal indentation