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>

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

Answer Source

You can use simple if's:

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