September 24, 2026

HTL data-sly-test: Conditional Rendering and If/Else

HTL sly-test

data-sly-test evaluates a condition and conditionally removes the host element and its content. If the expression is false, the element is removed; if it is true, the element is kept.

<h1 data-sly-test="${display}">text</h1>

Here the h1 element and its content are rendered only if display is true.

If/else in HTL

You can build an if/else with data-sly-test. The result of a test can be assigned to a variable and reused in later tests.

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

Combine it with the logical and comparison operators for more complex conditions.

Back to the HTL tutorial index