0

What I do is use the Thymeleaf attributes but I don't want to have for example an extra div.

For example, I have this

<div sec:authorize="hasRole('ROLE_ADMIN')">
    This content is only shown to administrators. 
</div>

But I'd like something like this:

<sec:authorize="hasRole('ROLE_ADMIN')">
    This content is only shown to administrators. 
</>

Is this possible?

3
  • 1
    What you have posted is not valid xml/html. Thymeleaf expects valid html (tags) with custom attributes that it can use to render a view. Commented May 13, 2013 at 15:36
  • Hi Sotirios, I know that is not valid, is an example of what I need. Do you know how to handle this? Commented May 13, 2013 at 15:43
  • What I was trying to say is, since HTML doesn't have such tags and Thymeleaf uses HTML tags to render templates, you won't be able to achieve what you want with Thymeleaf. Not as far as I know. Commented May 13, 2013 at 15:48

1 Answer 1

7

You can use the th:block tag:

<th:block sec:authorize="hasRole('ROLE_ADMIN')">
    This content is only shown to administrators. 
</th:block>

From the Thymeleaf docs:

th:block is a mere attribute container that allows template developers to specify whichever attributes they want. Thymeleaf will execute these attributes and then simply make the block dissapear without a trace.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.