HTL Operators

HTL Operators

Logical Operators
Logical Operators are used with Boolean values, where the operator returns the value of one of the specified operands. While using with non-Boolean values, they may return a non-Boolean value. They are of 3 types.
  • 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
Conditional operator can be used to define conditions within expressions.

Comparison Operators
Comparison Operators(equality and inequality operators) used to compare identical type operands.


  • Strings - equal - having the same sequence of characters.
  • Numbers - equal having the same value
  • Booleans - equal - when both are true or both are false.
  • Null or undefined variables - equal - to themselves and to each other.


Samples:

<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 longer or equal to 5 </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 HTL supports bracketing to ensure the preference of operation.

${thirdVar && (firstVar || secondVar)}

No comments:

Post a Comment