I wrote the following StringTemplate template lines:

<instance.attributes: { attr | <attr.value>}>
<instance.attributes: { attr | <if(attr.value)>skip<else>don't skip<endif> } >

in order to write skip if the Object value return by Instance.getAttributes().getValue() is a boolean which value is true.

This result in

1
skip

and

0
skip

(for now I only have one attribute)

What is the problem and why I don't get ?

0
don't skip
有帮助吗?

解决方案

From the StringTemplate wiki

<if(attribute)>subtemplate <else>subtemplate2 <endif> if attribute has a value or is a boolean object that evaluates to true, include subtemplate else include subtemplate2. These conditionals may be nested.

I assume that 0 means not false, but some value that indicates presence of value and evaluates to true. You need to compute boolean value that evaluates to false before pushing it to the template.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top