Template::Plugin::Haml caveats
Including other templates is tricky. Either you have to indent the included template as if it was pasted inline (eg. with a bunch of spaces in front of every line instead of the first level being column zero) or you have to format the include appropriately.
For example, let's say you have a content variable which was made by rendering some templates, you'd like to do something like:
%html
%body
#content
[% content %]
You want the embedded content to be location neutral, ie. start at column zero. Something like:
#myDiv
%ul
%li foo
Except this will be rendered AFTER the closing html tag since the combined haml will look like:
%html
%body
#content
#myDiv
%ul
%li foo
I'm going to try to think of some better way to resolve this, but for now I'm using the Template::Toolkit built in indent filter like so:
%html
%body
#content
[% content | indent(' ') %]
The only downside (apart from the pain of keeping it in sync) is that you end up with the rendered html having some funky indentation after the newlines are stripped, but I can live with that. You can use a number instead of a string as an argument to indent, and it will pad by that many spaces which may turn out to be easier to keep in sync.
I'll let you know if I have any flashes of genius and will also contact the Template::Plugin::Haml and Text::Haml authors.
08:00 AM, 29 Jul 2010 by Mark Aufflick Permalink






