Consider these TT commands (run in order):
[% x = "foo" %] # x == "foo"
[% x = "bar" IF 1 %] # x == "bar"
[% x = "bar" IF 0 %] # x == ""
Why does x get assigned to an empty string in the 3rd statement?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
http://template-toolkit.org/docs/manual/Syntax.html#section_Capturing_Block_Output
Note one important caveat of using this syntax in conjunction with side-effect notation. The following directive does not behave as might be expected:
In this case, the directive is interpreted as (spacing added for clarity)
rather than
The variable is assigned the output of the IF block which returns ‘value’ if true, but nothing if false. In other words, the following directive will always cause ‘var’ to be cleared.
To achieve the expected behaviour, the directive should be written as: