Fork me on GitHub

Of course this is the original Ruby implementation just works. Go Ruby!

alternative PHP implementations (attempts)

Summary: If there had been a working library I would not have spend days on writing this. Look at MtHaml below. Now there is an alternative. Do you want me to open source this library?

Wikipedia's page about Haml

Missing Link? Contact support.

It was announced recently on the haml mailinglist. Other languages can be added easily. I haven't had a look at it yet because it does not support PHP yet. Because its not written in PHP you'll have to compile haml templates statically always. Also it dose not support quoting nor does it support the simple "%div=$value" syntax. This works - but no quoting: "%div #{$value}"


flaws rev 90:


See my statement in the README. The parser will never be compliant without a rewrite. The author seems to be gone away ? No replies or updates for a long time.


The idea was to use a proper Parser lexer and grammar. Current status: broken which the author admitted. To make it work maybe a lot of more work has to be done. So they assigned higher priorities to other projects meanwhile...

Probbaly fixing it is not that hard: You could approximate PHP expressions the way its done in this library by rewriting this recursive regex in the grammar:

// (?R) matches to most outer regexp recursively
// That's something Ruby can't do (yet?)
// You can't just parse until you hit a ","
// because contents can be  %tag = substr(2,4,8)
// so the substr will be matched by "anything else", the (...) will be
// matched by the ", separated func args"

// keys are documentation only
$items = array(
  '" str' => '"([^"\\]+|[\\].)*"',
  "' str" => ''([^'\\]+|[\\].)*'',
  ', separated func args' =>  '(((?R)(,(?R))*))',
  'recursion in ()' => '((?R))', // this catches nested ( 2 + (4 + ) ) ..
  // '{(?R)}
  ' anything else but terminal' => "[^'"(){},n$s]+"
$regex ='('. implode('|',$items).')+';

phaml So if you don't want to pay for HAML-TO-PHP this could be an option - however not for production use. The simplicity is similar to hamlap (see below)


kohaml quote from README: "This module is old and outdated and does not yet work for Kohana V3. Instead take a look at a better implementation by Fred Wu here -". phamlp see above.


hamlap The parser engine is about 310 lines long. Mine is about slightly more than 1000. Thus this library must be incomplete. The test case does not cover interpolations ( #{"eg this"} ). There is no test suite. Like phamlp its using one huge regex (altthough this is more readable cause its concatenated by several vars). This can't match recursive putterns such as a=>(3 * (4+2)).

It does not force you to start a new line if you have multiple lines (you could live with that), but it neither implements both != and = assignments. Thus no quoting is provided. So this is yet another quick and dirty implementation not differing much from phaml (see above) which I can't recommend for those reasons for productive use unless you want to write HTML only without filling in data.


MtHaml Finally it looks like there is an usable alternative. It does not: I agree that you can get along without those features. Thus if do not want to buy mine try that - it looks like getting the job done as well.
Thanks to Boomy Jee for telling me about it

PHP jade implementation

JADE for PHP Jade is the template engine for node js. This PHP implementation does not support interpolations #{..}

SLIM - next generation Ruby template engine?

Ther are additional interesting Ruby libraries. Check out the ideas behind them before settling on HAML. Eg