htmlconditional-statementsaemsightly

HTL conditional rendering while not affecting nested html


Is it possible using HTL to not render a HTML element if a condition evaluates to false but still render the nested content? Example:

<A renderIf="${properties.value}">
   <B>my content</B>
</A>

If value is false then this would be rendered:

<B>my content</B>

If value is true this should be rendered:

<A>
   <B>my content</B>
</A>

Solution

  • This is exactly what data-sly-unwrap is for:

    <A data-sly-unwrap="${!properties.value}">
       <B>my content</B>
    </A>
    

    (note the inverted condition wrt your example because when data-sly-unwrap evaluates to true, it will unwrap the element, i.e. only display the contents).