Content may be conditionally processed using the "if" tag. This tag may be used in two forms: a bodiless form, which provides a value for one cell only, and with a body, which conditionally processes an entire block of cells.
The "if" tag evaluates the condition specified in the required attribute "test". If true, then the "if" tag transforms the entire body, and any "elseAction" value is ignored. If false, then the entire body is removed. Upon removal, content that lies below that block is shifted up to overwrite the block.
<jt:if test="${condition}">${expr1} | ||||
${expr2} | To be erased if false! | |||
${expr3} | ${expr4} | </jt:if> | ||
Shift | me | up! |
... if the condition is true, then the above block gets transformed into...
Expression 1 | ||||
Expression 2 | To be erased if false! | |||
Expression 3 | Expression 4 | |||
Shift | me | up! |
... else, if the condition is false...
Shift | me | up! | ||
The optional "elseAction" attribute controls how the content of the block is removed when the condition is false. The value "shiftLeft" changes the default direction of the shifting to left, i.e. content to the right of the block is shifted left to overwrite the block. The default value for this attribute is "shiftUp", which is shown above.
<jt:if test="${condition}" elseAction="shiftLeft">${expr1} | ${expr2} | Additional | ||
${expr3} | Content | |||
Label: | Is Shifted | |||
${expr4}</jt:if> | Left | |||
Below, | things | don't | change | !!! |
... if the condition is false...
Additional | ||||
Content | ||||
Is Shifted | ||||
Left | ||||
Below, | things | don't | change | !!! |
The elseAction value "clear" indicates not to perform any shifting of content outside of the block. Instead, values inside the block's cells are simply cleared. Other things such as borders, formatting, and merged regions remain intact.
<jt:if test="${condition}" elseAction="clear">${expr1} | ${expr2} | Additional | ||
${expr3} | Content | |||
Label: | Is Not Shifted | |||
${expr4}</jt:if> | Left | |||
Below, | things | don't | change | !!! |
... if the condition is false...
Additional | ||||
Content | ||||
Is Not Shifted | ||||
Left | ||||
Below, | things | don't | change | !!! |
The elseAction value "remove" also does not perform any content shifting outside of the block. However, unlike the "clear" value, "remove" will additionally remove the entire cells of the block, which removes all borders, merged regions, and formatting.
<jt:if test="${condition}" elseAction="remove">${expr1} | ${expr2} | Additional | ||
${expr3} | Content | |||
Label: | Is Not Shifted | |||
${expr4}</jt:if> | Left | |||
Below, | things | don't | change | !!! |
... if the condition is false...
Additional | ||||
Content | ||||
Is Not Shifted | ||||
Left | ||||
Below, | things | don't | change | !!! |
In the bodiless form, the "if" tag also requires a "then" tag, and it can accept an optional "else" tag. Rich Text String formatting is supported in the "then" and "else" attributes.
<jt:if test="${condition}" then="${value1}" else="${value2}"/> |
... if the condition is true...
Result1 |
... else if the condition is false...
Result2 |