About HAML

About HAML


HAML | Melkweg Technologies

HAML stands for HTML Abstracting Markup Language. HAML which is a markup language used for clean and simp appearance without the use of inline code of an HTML web document. The main function is a replacement for PHP, ASP, and ERB, which we call as inline page templating systems, mostly used in Ruby on Rails applications.

For development of HAML language, there is a adherence to several core principles which are as follow :

  1. Must have beautiful markup
  2. Should have dry markup
  3. Should be well-indented markup
  4. HTML Structure should be clear.


We will have a look at some basic ERB that we want to convert.

ERB to HAML conversion:

<strong><%= item.title %></strong>

After converting to HAML

%strong= item.title


In this language we write a tag by using the “%” (percent sign) and then the ‘name of the tag’.

For example we can place any tag such as %strong, %div, %body, %html, etc. After the tag sign “=” which says HAML to evaluate Ruby code to the right and then return value as the tag contents. HAML automatically detects return value in the new line and tag format properly.


<strong class="code" id="message">Hello, World!</strong>

Converted to HAML.

%strong{:class => "code", :id => "message"} Hello, World!

HAML is a layer on top of XML or HTML, which is designed to express the structure of documents in an easy way by using a deep recess rather than closing tags and allowing Ruby to be embedded. It was originally visualized as a plugin for Ruby on Rails but it can function as a stand-alone templating engine.

Convertion of ERB to HAML :



<div id='content'>

  <div class='left column'>

    <h2>Welcome to our site!</h2>

    <p><%= print_information %></p>


  <div class="right column">

    <%= render :partial => "sidebar" %>



After conversion :




    %h2 Welcome to our site!

    %p= print_information


    = render :partial => "sidebar"