Haml: Markup Haiku
Haml takes your gross, ugly templates and replaces them with veritable Haiku. Haml is based on one primary principal: markup should be beautiful. Check out http://haml.hamptoncatlin.com/.
This is a guide to using Haml in CakePHP instead of the normal .ctp/.thtml files. Note: this uses phphaml which is for PHP5.
First of all, download the HamlParser and HamlView from http://cakeforge.org/snippet/detail.php?type=package&id=35. Place HamlParser.class.php in the app/vendors/haml/ directory and place haml.php in the app/views/ directory. Create the directory app/tmp/haml and make it world-writable (chmod 0777). This is where the compiled php files are placed. Next, in your AppController, put var $view = 'Haml';. Now all view files with the extension '.haml' will be parsed as Haml. That's it!
Here's a sample Haml layout (app/views/layouts/default.haml):
And here's a sample view (app/views/hello/index.haml):
As you can see, using helpers inside Haml is no trouble at all.
First of all, download the HamlParser and HamlView from http://cakeforge.org/snippet/detail.php?type=package&id=35. Place HamlParser.class.php in the app/vendors/haml/ directory and place haml.php in the app/views/ directory. Create the directory app/tmp/haml and make it world-writable (chmod 0777). This is where the compiled php files are placed. Next, in your AppController, put var $view = 'Haml';. Now all view files with the extension '.haml' will be parsed as Haml. That's it!
Here's a sample Haml layout (app/views/layouts/default.haml):
!!! Strict
%html
%head
%meta{ :http-equiv => 'Content-Type', :content => 'text/html;charset=utf-8' }
%title= $title_for_layout
%body
#header
%h1 hello
#content= $content_for_layout
#footer
%span.author John Q. Caker
And here's a sample view (app/views/hello/index.haml):
.hello
%p Hello, world!
= $html->link('This is a link to the home page', '/')
As you can see, using helpers inside Haml is no trouble at all.








"while(ob_get_level() > 0) {
ob_end_flush();
}"
- ASP.NET MVC Framework (NHAML)
- Ruby (origin)
- Multiple implementations for PHP (PHPHAML on SF (as above) & pHAML)
If you're interested in the 'viability', or rather, how it can help you, check out the HAML entry on Wikipedia, that will help answer your questions. And, as always, TMTOWTDI.
Comments are closed for articles over a year old