Thymeleaf:在片段参数中使用文字

时间:2018-04-26 14:17:21

标签: spring templates spring-boot thymeleaf

在模板header中,我有

<head th:fragment="common_header(title)">
  <title th:replace="${title}">Default title</title>
  <meta charset="utf-8" />
  ...
</head>

我尝试在参数:

中使用文字
<head th:replace="~{header::common_header(title='This should be real title')}">
  <title>Just for template's sake...</title>
  <meta charset="utf-8" />
  ...
</head>

但我得到的只是

org.thymeleaf.exceptions.TemplateInputException: Error resolving template "This should be real title", template might not exist or might not be accessible by any of the configured Template Resolvers (template: "header" - line 4, col 9)

我做错了什么?使用_(无操作令牌)产生Default title(如预期的那样)

1 个答案:

答案 0 :(得分:1)

属性th:replace需要模板表达式,而不是文本变量。如果将其更改为:

,它是否有效
<title th:text="${title}">Default title</title>