Badger Book thoughts

Gervase Markham gerv at
Sun Mar 21 13:19:27 UTC 2004

I've been looking through the Badger Book (the new O'Reilly volume on 
the Template Toolkit.) I came up with the following thoughts/ideas:

- Contrary to my understanding, the form:
   [% FOREACH foo IN bar %]
   is supported. We should use it (i.e. IN instead of =) for clarity.

- There is a useful DEBUG option allowing you to spot use of undefined
   variables. You invoke it when the template is constructed (in our
   case, in Bugzilla::Template->create):
   my $template = Template->new({

- There is a Date plugin which formats dates. I seem to remember we
   haven't been using this because of rumours of Win32 issues. But we
   should re-investigate.

- [% somescalar.chunk(n) %] splits a scalar into a list of chunks of n

- Unlike Perl, TT has a SWITCH directive, which works on both numbers
   and strings.
   [% SWITCH foo %]
     [% CASE "Fred" %]
     [% CASE "Barney" %]
   Note that there is no case fallthrough. We should consider using this
   in e.g. the error templates.

- There is a URL plugin which we should probably use when assembling
   long URLs (which we often do in charting, for example.)
   Instead of:
      <a href="buglist.cgi?cmdtype=dorem&namedcmd=
         [% series.category FILTER url_quote %]%20/%20
         [% series.subcategory FILTER url_quote %]%20/%20
         [% FILTER url_quote -%]&series_id=
         [% series.series_id %]&remaction=runseries">Run Search</a>
   [% buglist = url("buglist.cgi") %]
   [% buglist(cmdtype='dorem') %]
   [% namedcmd = "$series.category / $series.subcategory / $"
                                                     FILTER url_quote %]
   [% buglist(namedcmd=$namedcmd) %]
   [% buglist %] on its own (no params) outputs the URL.

- Last but not least, one of my own. PRE_CHOMP is great for making
   output more readable; the one trick you need to remember is not to
   start a line with a directive if you want a space between it and the
   previous bit of text.


More information about the developers mailing list