Art Of Programming

musings by Dmytrii Nagirniak

NHAML – Impressions

I have introduced the NHAML into a new project. Just can’t silently ignore it. This is great thing. Really great. It does save time and helps to concentrate on the presentation of the view in ASP.NET MVC. I just love. Additionally it has great coverage of unit tests and code looks really good. So I believe in its quality.

This is the quote:
“Haml is a markup language that‘s used to cleanly and simply describe the XHTML of any web document, without the use of inline code. Haml functions as a replacement for inline page templating systems such as PHP, ERB, and ASP. However, Haml avoids the need for explicitly coding XHTML into the template, because it is actually an abstract description of the XHTML, with some code to generate dynamic content.”
In other words, NHaml is an external DSL for XHTML. It’s primary qualities are it’s simplicity, terseness, performance and that it outputs nicely formatted XHTML. Additionally, the NHaml view engine provides support for Rails style layouts and partials and ships with an ASP.NET MVC view engine.

Why do you want to use NHAML:
  • Want to write less code.
  • Do not want to repeat the HTML closing tags.
  • Want to generate valid XHTML easier.
  • Tired of chaging type of the model in ASPX.
  • Tired of writing
    <%= Server.HtmlEncode(Model.Name) %>
  • Want to keep it simple.
  • Want mark-up to drive the rules and not code.
Why you don’t:
  • Want to have intelly-sence in the view.
  • Want to use Visual Studio MVC integrated features:
    • Go to Controller (from view)
    • Go to View (from controller action)
    • Add view (from controller action)
  • Don’t want to bother with new syntax (even when it takes minutes to learn)
I thought about Spark view engine. It promotes that the presentation drives the rules but not code. But still NHAML suits me  much better and it drives the presentation much better.
You’ll find enough on the Internet on the NHAML. Don’t forget to view the reference as there are some changes to the syntax that might not be reflected in topics on the net.
Also don’t forget to say thanks to guys working on it by donating (see the button at the bottom) them.
I plan to post couple of tips on it later.

Comments