Thymeleaf Conditional Expressions? th:class th:text

	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>

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *