user1941537
user1941537

Reputation: 6675

Sightly - Show the header tag only if there is a header

Using HTL (Sightly) I want to display

<h2 data-sly-text="${model.heading}"></h2>

But only if the ${model.heading} is not empty, otherwise nothing, not even the h2 tag.

I tried the following solution, but it didn't work:

<sly data-sly-test="${model.heading}"><h2 data-sly-text="${model.heading}"></h2></sly>

Upvotes: 1

Views: 85

Answers (1)

Vlad
Vlad

Reputation: 10780

You can just write it as:

<h2 data-sly-test="${model.heading}" data-sly-text="${model.heading}">Heading placeholder</h2>

The snippet you posted should have worked too, since you did not mention what was not working I can suggest:

  • checking the model variable is properly defined and initialised
  • checking the heading property is properly exposed (either directly or via a getHeading method)

Upvotes: 2

Related Questions