[Templates] Chomping whitespace

darren chamberlain dlc@users.sourceforge.net
Wed, 18 Sep 2002 15:00:43 -0400


* Hann, Brian <Brian.Hann@umb.com> [2002-09-18 14:46]:
> I know you can use [%- and -%] to chomp newlines without having to use
> PRE_CHOMP and POST_CHOMP, but is there a way to remove ALL whitespace
> before/after a directive without having to use configuration options?

Hm...  Wrap everything with the collapse filter:

  [% FILTER collapse %]

  Your content here

  [% END %]

See the Template::Filters perldoc.

  collapse
      "collapse" replaces any amount of whitespace with a
      single space character.  "collapse" uses Perl's defi-
      nition of whitespace, which includes spaces, tabs,
      carriage returns, newlines, and a few more esoteric
      characters.

          [% FILTER collapse %]
              You'll   love
                it,   it's             a    way
                    of      life.
          [% END %]

      The output is nice and clean:

          You'll love it, it's a way of life.

(darren)

-- 
Those who learn from history are doomed to have it repeated to
them anyway.
    -- Larry Wall