Haml 3.2 is due to be released soon (rc3 has just been released), and there should be a new haml-contrib
gem released along with it. haml-contrib
has a PHP filter that might be what you’re looking for.
The doc comment for the php filter says:
# A PHP Filter for Haml. This simply wraps code inside <?php ?> tags. While this
# may seem like a strange idea, some people use Haml to generate mostly static
# HTML documents that then include small amounts of PHP.
#
# This code also serves as an example of how to implement a simple filter for
# Haml.
It doesn’t really do much more than the :plain
filter in Kevin Granger’s answer, but might make things slightly easier.
An example:
$ cat php.haml
:php
foreach ($es as $e) {
echo $e;
}
$ haml -rhaml/filters/php php.haml
<?php
foreach ($es as $e) {
echo $e;
}
?>