【问题标题】:Thymeleaf does not take localization in th:includeThymeleaf 在 th:include 中不进行本地化
【发布时间】:2014-09-14 09:28:05
【问题描述】:

我尝试将 Spring 的本地化包与 Thymeleaf 模板一起使用。如果在普通模板中使用它效果很好,但如果我在容器标签处应用 th:include 属性会失败。

我把视图代码放到Gist:https://gist.github.com/hron84/386bbf855148a601a3dc

有问题的本地化在第 4 行和第 10 行。在第 10 行中,我看到了正确的扩展(“新机器”),但在第 4 行中,我只是将“null”作为页面标题。

你能指出我做错了什么吗?

【问题讨论】:

    标签: spring spring-mvc internationalization thymeleaf


    【解决方案1】:

    正如 Martin 所说,您的 th:include 正在替换您的标题标签,您应该这样做:

    <head>
        <title th:text="#{page.title.machine.new}">&nbsp;</title>
        <dif th:include="widgets/_head :: head" th:remove="tag"></dif>
    </head>
    

    th:remove="tag" 将删除 diff 标签。

    Thymeleaf 网站有一些有用的documentation about the th:include and th:replace tags

    【讨论】:

      【解决方案2】:

      使用 th:include 您正在用从片段中获取的内容替换内部内容,即标题标签。由于您没有发布头部片段模板,因此我无法为您提供更多提示。我怀疑你在头部片段中的标题标签对标题标签做了不同的事情?

      【讨论】:

      • 我猜,th:include 混合了这两个内容,因为有一个 th:replace 用于替换,但我不确定......标题片段不包含标题标签。奇怪的是我在响应 html 中有标题标签,只是本地化没有扩展。
      • 我用一个包含主视图和包含模板的新链接更新了问题。
      猜你喜欢
      • 2017-12-24
      • 1970-01-01
      • 1970-01-01
      • 2016-07-17
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多