Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Conditional text in ThymeLeaf : how to do it in plain text?

I understand how th:if works for html templates, but I don't find any clue on how to do it when you expect plain text (use case : plain text e-mail templating).

So far I tried :

<html xmlns:th="http://www.thymeleaf.org" th:inline="text" th:remove="tag">
  Dear [[${contact.firstname}]] [[${contact.lastname}]],
  An alert was triggered at location:  [[${account.address}]] 
  <span th:if=\"${videoLink}\">To view your security camera recordings, please click on [[${videoLink]]</span>
</html>

It works... but the result contains the tag. Any idea of what I'm doing wrong ?

Thanks, Cyril

like image 970
Cyril Dejonghe Avatar asked Jun 03 '15 10:06

Cyril Dejonghe


1 Answers

Thymeleaf 2.1 has a th:block tag, which is basically a container for attributes. Your conditional text can be done like this:

<th:block th:if="${videoLink}">To view your...</th:block>
like image 70
cnpfm Avatar answered Sep 30 '22 08:09

cnpfm