PHP Implementation of Haml
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


Limber Haml

Haml is a template engine for the common type HTML This is one PHP implementation using the same specification of original next3/haml

This document is a modified version of the original one created at Ruby Haml project(link above) with previous authorization of the author


Just download the package (using git or manual download here), extract at a folder of your preference and require the file haml.php at folder lib.



require "haml/lib/haml.php";

$haml = new Haml();
$haml_code = file_get_contents("my_template.haml");
$html_code = $haml->parse($haml_code);

echo $html_code;



The most basic element of Haml is a shorthand for creating HTML tags:

%tagname{attr1='value1' attr2='value2'} Contents

No end-tag is needed; Haml handles that automatically. Adding class and id attributes is even easier. Haml uses the same syntax as the CSS that styles the document:


In fact, when you're using the <div> tag, it becomes even easier. Because <div> is such a common element, a tag without a name defaults to a div. So

#foo Hello!


<div id='foo'>Hello!</div>

Haml uses indentation to bring the individual elements to represent the HTML structure. A tag's children are indented beneath than the parent tag. Again, a closing tag is automatically added. For example:

  %li Salt
  %li Pepper



You can also put plain text as a child of an element:


It's also possible to embed PHP code into Haml documents. An equals sign, =, will output the result of the code. A hyphen, -, will run the code but not output the result. You can even use control statements like if and while:

  - $now = date("d/m/Y H:i:s")
  %strong= $now
  - if strtotime(now) > strtotime("December 31, 2006")
    = "Happy new " . "year!"

Haml provides far more tools than those presented here. Check out the reference documentation in the project wiki.


Actually Limber Haml supports only identation with one tab. In newer versions we will implement support for any consistent identation that user needs (with n number of tabs/spaces)