English 中文(简体)
Bugzilla templates: what s the difference between [% and [%+
原标题:

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 %]
最佳回答

[%- (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 [~ :)).

问题回答

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.





相关问题
How to change out-of-focus text selection color in Xcode?

Okay, I ll bite. I ve got really pleasant code/window colors set up in Xcode. Ordinarily, my selection color is very visible. When I am doing a project search and iterating through the results, ...

pdo database abstraction

Can someone help me to see what is going wrong with this setup I build the @sql query in the function below like this. The extra quotes are setup in the conditions array. $sql .= " WHERE $...

I wish I could correlate an "inline view"

I have a Patient table: PatientId Admitted --------- --------------- 1 d/m/yy hh:mm:ss 2 d/m/yy hh:mm:ss 3 d/m/yy hh:mm:ss I have a PatientMeasurement table (0 to ...

Syntax help! Php and MYSQL

Original: $sql = "SELECT DATE(TimeAdded) AS Date, $column_name FROM Codes ORDER BY TimeAdded ASC"; Altered: $sql = "SELECT DATE("m", TimeAdded ) AS Date, ColumnName FROM TableName ORDER BY ...

Is this code Equivalent

I am not a fan of the following construction if (self = [super init]) { //do something with self assuming it has been created } Is the following equivalent? self = [super init]; if (self != ...

热门标签