HTL sly-test





<data-sly-test/> Validates and conditionally removes the host element and it's content. Returned 'False' removes the element; Returned value 'true' retains the element.

For eg:
<h1 data-sly-test="${display}">text</h1>
Here h1 element and its content will only be rendered if 'display' is true.

Create if-else in HTL.
We can construct if-else by utilising data-sly-test. The result of a test can be assigned to a variable. This can be utilised for future validations.

For eg:
<h1 data-sly-test.myVar="${x || y || z}">is true</h1>
<h1 data-sly-test="${!myVar}">Else This</h1>

Go to HTL Tutorial Home page
 

No comments:

Post a Comment