Badger Book thoughts
Gervase Markham
gerv at mozilla.org
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({
DEBUG => DEBUG_UNDEF,
});
- 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
characters.
- 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
[% series.name FILTER url_quote -%]&series_id=
[% series.series_id %]&remaction=runseries">Run Search</a>
do:
[% buglist = url("buglist.cgi") %]
[% buglist(cmdtype='dorem') %]
[% namedcmd = "$series.category / $series.subcategory / $series.name"
FILTER url_quote %]
[% buglist(namedcmd=$namedcmd) %]
etc.
[% 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.
Gerv
More information about the developers
mailing list