Tuesday, July 28, 2009

Template Toolkit Tip for the Week

For the love of god, why did it take me 3 months to find a command to chomp white space? You're sick unto death of having to view the source of your html after a template has produced it and it's full of blank lines? Follow the link. All you need to do is add a "-" to your template toolkit markup.

[% some command here %]

becomes

[% some command here -%]

I suppose the overarching meta point here? Read documentation even when you don't think you need it directly for the task at hand. You'll find all sorts of goodies in there.

1 comment:

  1. If you have control over the bit of code which creates the Template processor object itself, you can pass new() a parameter that chomps whitespace:

    Template->new( POST_CHOMP => 1, .... )

    (Found this in the source of CGI::Prototype::Hidden)

    Which means you can keep writing

    [% foo %]

    Instead of

    [% foo -%]

    ReplyDelete