【问题标题】:Thymeleaf: Using literals in fragment's parameterThymeleaf:在片段的参数中使用文字
【发布时间】:2018-10-07 06:59:56
【问题描述】:

在模板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(如预期)

【问题讨论】:

  • /template 文件夹中有您的header 模板吗? header 文件的第 4 行是什么?
  • @BennettDams 是的,我有。第四行是&lt;title th:replace="${title}"&gt;Default title&lt;/title&gt;

标签: spring templates spring-boot thymeleaf


【解决方案1】:

属性th:replace 需要一个模板表达式,而不是一个文本变量。改成这样行不行:

<title th:text="${title}">Default title</title>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-04-01
    • 2020-06-02
    • 1970-01-01
    • 2017-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多