ThymeLeaf 中的条件文本:如何以纯文本形式进行?

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

我了解 th:if 如何用于 html 模板,但我没有找到任何关于如何在您期望纯文本时执行此操作的线索(用例:纯文本电子邮件模板).

到目前为止我试过了:

<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>

有效...但结果包含标签。知道我做错了什么吗?

谢谢, 西里尔

似乎与 th:inline 不同,th:remove="" 未应用于子节点,必须为每个标签添加。在这里,如果我将它添加到标签中,结果就是我想要的:

<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}\" th:remove="tag">To view your security camera recordings, please click on [[${videoLink]]</span>
</html>
结果:

Dear John Doe,
An alert was triggered at localation: 205 North Michigan Avenue Chicago, IL

To view your security camera recordings, please click on http://www.video.com?id=007   

Thymeleaf 2.1 有一个 th:block 标签,它基本上是属性的容器。您的条件文本可以这样完成:

<th:block th:if="${videoLink}">To view your...</th:block>