views:

91

answers:

2

Code in Bugzilla templates is usually delimited by [% and %]. But sometimes I see [%+ and [%-. Can someone explain the difference or point me at suitable documentation? Google has failed me on this occasion.

For example:

[%- event.value.subject FILTER html %]

or

[%+ END %]
+2  A: 

[%- (or -%]) removes leading (trailing) whitespace; [%+ (or +%]) maintains it. See PRE_CHOMP, POST_CHOMP in the Template Toolkit Manual (Bugzilla templates use the Template Toolkit) for the gory details (including [= and [~ :)).

ax
+2  A: 

Here's something I wrote for our team last year:

I was less informed about TT's behavior than I should have been, and another member of our team has confessed to me that he was even less informed than I was!

This is a brief explanation of how chomping works.

Suppose I have the following template, with the variable x = 'foo'

<td>
  [% x %]
</td>

will become

<td>
  foo
</td>

Note the spaces at the beginning of the second line.

TT has configuration settings for PRE_CHOMP and POST_CHOMP.

If PRE_CHOMP is 1, then all the whitespace in front of a directive, including a newline, is removed. The example becomes

<td>foo
</td>

If POST_CHOMP is 1, then the opposite occurs on the other end:

<td>
foo</td>

If PRE/POST_CHOMP is 2, then all preceding/succeeding whitespace is collapsed to a single space:

<td> foo </td>

If PRE/POST_CHOMP is 3, then all preceding/succeeding whitespace is eliminated:

<td>foo</td>

==IMPORTANT==

Bugzilla is configured with PRE_CHOMP = 1. POST_CHOMP is not set.

You can explicitly denote chomping behavior with one of the characters -, =, ~, and + after the '[%' or before the '%]'. '-' denotes CHOMP level 1, = denotes CHOMP level 2, ~ denotes CHOMP level 3, + denotes no chomping regardless of whether it is set in the overall configuration.

So to repeat the example:

<td>
  [% x %]
</td>

Because we have PRE_CHOMP = 1, then this will become

<td>foo
</td>

<td>
[%- x -%]
<td>

becomes

<td>foo</td>

<td>
[%= x =%]
</td>

becomes <td> foo </td>

<td>

[%~ x ~%]

</td>

becomes <td>foo</td>

Finally,

<td>
  [%+ x %]
</td>

becomes

<td>
  foo
</td>

For an even more verbose explanation, do 'perldoc Template::Manual::Config' and search for CHOMP.

David M