dxw edited this page Sep 13, 2010 · 4 revisions
Clone this wiki locally

Fammel: a HAML parser for PHP

Fammel is a HAML parser written in PHP. You can use Fammel to write your PHP views (or indeed,. your whole application, if you’re mad) instead of embedded PHP.

We’ve built fammel from the ground up to be robust. It uses a grammar. It has error reporting. It’s easy to use:

include "fammel.php"
$fammel = new Fammel();
file_put_contents('compiled_template.php', $fammel->render());

Fammel is still in very early development, and is not yet ready for production use — but don’t let that stop you playing. There are sure to be lots of bugs, which we’d definitely appreciate some help with!

For a list of known issues/todos, visit the issue tracker.

Where do I get it?

For now — just clone this repository.

Tell me more things

What’s with the silly name?

Fammel == phaml == php haml

Why did you build this when there are already other parsers like pHAML and phpHaml?

We tried pHAML and phpHaml, which are the only ones we could find.

pHAML didn’t work very well for us because it requires you to include compiled templates from within a method in one of its classes. You can’t compile a template and save it as a standalone PHP script.

phpHaml was more suitable, but ultimately it didn’t work well for us either. It had some frustrating bugs, but it was primarily the lack of error reporting that made us drop it — obviously invalid HAML just gets compiled into obviously broken PHP, which is not ideal. The code was a nest of regexs, which made it hard to fix.

Ok. What does Fammel do differently?


  • Compiles your code into standalone PHP scripts which you can then include in your application, cache, etc.
  • Works using a grammar, which means it’ll give you sensible error messages when your code is wrong.
  • Sticks as closely to the original HAML implementation as possible. See the documentation for more details.
  • Has oodles of automated tests, which should help keep things on the straight and narrow

Give it a go, and let us know what breaks!