santafebound santafebound - 4 years ago 171
Java Question

Hide a button in Springboot/Thymeleaf application if not logged in

I'm trying to hide a button in the header of my Spingboot application in the following way with my markup:

<!-- Is not logged in, so don't show "Log In" -->
<li sec:authorize="!isAuthenticated()">
<a href="/login" th:href="@{/login}" class="btn-login">Log In</a>
</li>\


Is this not correct? I'm using the Thymeleaf templating engine.

Answer Source

You can use simple if's: http://www.thymeleaf.org/doc/tutorials/2.1/usingthymeleaf.html#simple-conditionals-if-and-unless

But you have to put the objects, you use in the if's, before into the (Spring) Model

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download