Logical operators
Logical operators are used with Boolean values and return the value of one of their operands. Used with non-Boolean values, they may return a non-Boolean value. There are three.
AND: <p data-sly-test="${properties.jcr:title && properties.jcr:description}">DISPLAY</p>
OR: <p data-sly-test="${properties.jcr:title || properties.jcr:description}">DISPLAY</p>
NOT: <p data-sly-test="${!currentPage.hasChild}">DISPLAY</p>
Conditional (ternary) operator
The conditional operator defines a condition inside an expression.
${properties.showTitle ? currentPage.title : 'Untitled'}
Comparison operators
The equality and inequality operators compare operands of the same type:
- Strings are equal when they have the same sequence of characters.
- Numbers are equal when they have the same value.
- Booleans are equal when both are true or both are false.
- Null or undefined variables are equal to themselves and to each other.
<div data-sly-test="${properties.jcr:title == 'true'}">TRUE</div>
<div data-sly-test="${properties.jcr:title != 'true'}">FALSE</div>
<div data-sly-test="${properties['jcr:title'].length > 5}">Title is longer than 5</div>
<div data-sly-test="${properties['jcr:title'].length >= 5}">Title is 5 or longer</div>
<div data-sly-test="${properties['jcr:title'].length > myArray.MAX_LENGTH}">
Title is longer than the limit of ${myArray.MAX_LENGTH}
</div>
Grouping parentheses
As in other languages, parentheses set the order of evaluation.
${thirdVar && (firstVar || secondVar)}