NHaml, an alternative view engine for ASP.NET MVC written by Andrew Peters, uses indentation instead of opening and closing tags to identify code blocks.

If you never saw something written in NHaml here is taste of it. If you want to loop over a list and put it inside a unordered list with webform you would write:

<div class="list">
  <ul>
    <%foreach (var route in ViewData.Model) { %>
      <li><%= route.Name %></li>
    <% } %>
  </ul>
</div>

The same code in NHaml will be:

.list
  %ul
    - foreach (var route in ViewData.Model)
      %li
        = route.Name

The biggest problem of NHaml is that it’s behavior depends on the number of spaces you put at the beginning of the line: one level of indentation is made by 2 whitespaces.

Yesterday Andrew wrote a post on his site announcing the beta of NHaml version  2, and a few people, including me, complained that the default indentation of Visual Studio is 4 spaces, but someone even uses tabs. So, he made quick change in the code, and now NHaml features a configurable indentation (2, 3, 4, 5 spaces or even tabs). A very quick response to users’ requests, well done Andrew.

Technorati Tags: ,