Begin main content

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:

      [% content %]

You want the embedded content to be location neutral, ie. start at column zero. Something like:

    %li foo

Except this will be rendered AFTER the closing html tag since the combined haml will look like:

    %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:

      [% 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 | Comments (0)

Using Haml with Catalyst

Thanks to Viacheslav Tykhanovskyi's Text::Haml, we can now enjoy the good clean fun of Haml markup in Perl. Much Perl web templating is done with Template::Toolkit, and using Haml within TT is also now possible thanks to Template::Plugin::Haml by Caleb Cushing. The trouble is, you need to wrap every template in some boilerplate:

[%- USE Haml ; FILTER haml -%]
[%- END -%]

So I hacked up a quick solution to using .haml templates directly in Catalyst. First, create a MyApp::View::Haml class:





    TEMPLATE_EXTENSION => '.haml',
    render_die => 1,

subrender {
    my ($self, $c, $template, $args) = @_;

    $c->log->debug(qq{Rendering Haml/TT template "$template"}) if$c && $c->debug;

    # args may be passed in or be in the stash
$args = { %{ $c->stash} }

    # let the master haml template know which template to render
$args->{haml_template} = $template;

    # do the normal TT render
return$self->SUPER::render($c, '', $args);


Then you need a template:

[%- USE Haml ; PROCESS $haml_template | haml -%]

And finally set your config to use the Haml view by default:

default_view => 'Haml'

Et voila - .haml template rendering albeit with only TT style variable interpolation. Getting haml interpolation working might need some change to how the stash is passed to the Text::Haml module.

A controller method might look like this:

subfoo:Global {
    my ($self, $c) = @_;

    $c->stash(foo => 'bar');
    $c->stash(template => 'foo.haml');

And foo.haml:

!!! HTML%body%p This is haml inside TT rendering your variables: [% foo %]

Becomes rendered as:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""">
<p>This is haml inside TT rendering your variables: bar</p>

04:35 AM, 29 Jul 2010 by Mark Aufflick Permalink | Comments (0)

Cauliflower, Potato and Carrot Puree

Our weekly fruit and veg delivery from Doorstep Organics arrived today which meant we had to use up some older produce with todays dinner. We had a fair amount of cauliflower and some carrots so I decided to make a puree. I started with an idea from New Larousse Gastronomique for a carrot and parsnip puree and came up with the following:

  • 200g potato
  • 100g carrot
  • 2 small onions
  • 600g cauliflower
  • 1-2 garlic cloves
  • 2 cups stock (I used chicken, but I think vegetable would be better)

Loosely chop all the ingredients. Melt some butter and olive oil in a pan. Saute carrott and potato, seasoning lightly. Add onion and garlic, then cauliflower. Cook for a while then partially cover with stock and vigorously simmer with the pan loosely covered (e.g. with a wok lid). When vegies are becoming soft, remove lid and continue cooking until almost all the liquid has evaporated. Puree until smooth in a blender.

I served it with some delicious organic sausages and steamed broccoli. This would be enough for at least six, or you can refrigerate and use over a few days.

07:27 AM, 26 Jul 2010 by Mark Aufflick Permalink | Comments (0)

Where'd everybody go?

Where'd everybody go?

Our neighbour has a great deciduous tree that attracts loads of birds in summer. Some birds seem not to mind when all the leaves disappear (into our yard)

Series home:

Taken with Canon EOS 400D DIGITAL and EF24-85mm f/3.5-4.5 USM on 2010:07:25 15:28:15

  • Exposure: 1/160
  • Aperture: f22.0
  • ISO speed: 100
  • Exposure program: Aperture-priority AE
  • Exposure compensation: -2
  • Flash: Off, Did not fire
  • File: _MG_3822.jpg

02:57 AM, 25 Jul 2010 by Mark Aufflick Permalink | Comments (0)

Sun at last

Sun at last

We haven't had too much sun this winter in Sydney, so it's always a welcome friend

Series home:

Taken with Canon EOS 400D DIGITAL and EF24-85mm f/3.5-4.5 USM on 2010:07:25 15:25:50

  • Exposure: 1/125
  • Aperture: f22.0
  • ISO speed: 100
  • Exposure program: Aperture-priority AE
  • Exposure compensation: 0
  • Flash: Off, Did not fire
  • File: _MG_3811.jpg

02:54 AM, 25 Jul 2010 by Mark Aufflick Permalink | Comments (0)


Blog Categories

software (41)
..cocoa (23)
  ..heads up 'tunes (5)
..ruby (6)
..lisp (4)
..perl (4)
..openacs (1)
mac (21)
embedded (2)
..microprocessor (2)
  ..avr (1)
electronics (3)
design (1)
photography (26) and white (6)
..A day in Sydney (18)
..The Daily Shoot (6)
food (2)
Book Review (2)


Icon of envelope Request notifications

Syndication Feed


Recent Comments

  1. Mark Aufflick: Re: the go/Inbox go/Sent buttons
  2. Unregistered Visitor: How do make a button to jump to folder
  3. Unregistered Visitor: Note I've updated the gist
  4. Unregistered Visitor: umbrello is now an available port on macPorts
  5. Unregistered Visitor: Updated version on Github
  6. Unregistered Visitor: Modification request.
  7. Unregistered Visitor: Accents and labels with spaces
  8. Unregistered Visitor: Mel Kaye - additional info
  9. Unregistered Visitor: mmh
  10. Mark Aufflick: Thank you