Thymeleaf Conditional Expressions? th:class th:text

Posted by dogukanhan on September 03, 2018 · 1 min read
model.addAttribute("variable", "dogukan");
	model.addAttribute("variableBoolean",false);
	model.addAttribute("variableBoolean2",true);

 

<p th:text="${variableBoolean}? 'it is true' : 'it is false'"> Text </p>

=it is false

<p th:text="${variableBoolean2}? ${variable} : 'it is false'"> Text </p>

=dogukan

<p th:text="${variable}" th:class="${variableBoolean2}? text-red : text-blue"> Text </p>

=<p class=”text-red“>dogukan</p>