Question

I end up with a lot of code like:

<section layout:fragment="content" th:remove="tag">
    <p>content section</p>
</section>

and

<section th:switch="${session['SOME_KEY'" th:remove="tag">
    <section th:case="${'BadCredentialsException'}" th:remove="tag">
        Invalid username/password
    </section>
    <section th:case="${'UsernameNotFoundException'}" th:remove="tag">
        Invalid username/password
    </section>
    <section th:case="${'DisabledException'}" th:remove="tag">
        Account is blocked, contact your admin
    </section>
    <section th:case="*" th:remove="tag">
        Something went wrong
    </section>
</section>

Note the th:remove="tag" to not display the in this case section tags as I don't neem them.

Is this the proper way to do this?

Was it helpful?

Solution

Since Thymeleaf 2.1 there's a sythetic th:block tag available. It's container attribute that is removed after execution (see documentation).

So you end up with code like this :

<th:block layout:fragment="content">
    <p>content section</p>
</th:block>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top