【问题标题】:Evaluating expressions in thymeleaf fragment评估百里香片段中的表达
【发布时间】:2018-10-29 09:42:33
【问题描述】:

我正在尝试评估来自百里香片段的表达式。但似乎一切都只是转换为字符串。

这是我的主模板中的内容

[(~{text:default_voucher::voucher-code})]

而voucher-code 片段看起来像

<th:block th:fragment="voucher-code">${Voucher_code}</th:block>

但Voucher_code 的值确实会显示出来。而是只显示文本 ${Voucher_code}。

在我的主模板中,如果在此处引用变量而不是使用片段,则会显示凭证代码。

[[${Voucher_code}]]

有没有办法让它工作?

更新 我通过更改主模板以包含像

这样的片段来让它工作
<th:block th:insert="~{text:default_voucher::voucher-code}" />

【问题讨论】:

    标签: thymeleaf


    【解决方案1】:

    您不会在 Thymeleaf 中显示这样的值:

    <th:block th:fragment="voucher-code">${Voucher_code}</th:block>
    

    Thymeleaf 评估标签属性内的表达式。

    因此,它应该是这样的:

    <th:block th:fragment="voucher-code">
        <p th:text="${Voucher_code}"></p>
    </th:block>
    

    【讨论】:

      猜你喜欢
      • 2017-06-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-29
      • 2012-09-21
      • 2018-07-08
      • 2020-11-28
      相关资源
      最近更新 更多