blc标签中的Thymeleaf th标签

时间:2016-09-08 07:05:53

标签: thymeleaf broadleaf-commerce

我的问题如下: 在此代码中

    <header>
        <h1 th:utext="${BLC_PAGE.pageFields[menu_name]}"></h1>
    </header>

    <blc:menu resultVar="menuItems" menuName="${BLC_PAGE.pageFields[menu_name]}" />
    <ul th:if="${not #lists.isEmpty(menuItems)}">
        <li th:each="menuItem : ${menuItems}">

            <a th:href="@{${menuItem.url}}" th:class="${menuItemStat.first}? 'home'">
                <span th:utext="${menuItem.label}"></span>
            </a>

        </li>
    </ul>

<h1 th:utext="${BLC_PAGE.pageFields[menu_name]}"></h1>获取实际菜单的名称。我需要此行<blc:menu resultVar="menuItems" menuName="${BLC_PAGE.pageFields[menu_name]}" />中的menuName执行相同的操作,但"${BLC_PAGE.pageFields[menu_name]}"不合适,因为它来自百万富翁标签库。知道怎么在blc:menu标签中得到这个值吗?

1 个答案:

答案 0 :(得分:1)

为了解决Thymeleaf表达式${BLC_PAGE.pageFields[menu_name]},您需要像这样包装它:th:attr="menuName=${BLC_PAGE.pageFields[menu_name]}"。因为menuName不是标准HTML属性,所以您将无法简单地将Thymeleaf命名空间添加到menuName(即th:menuName),并且在没有th:命名空间的情况下,Thymeleaf不知道它需要解决任何表达式。 Thymeleaf attr属性允许您使用Thymeleaf的非标准HTML属性。有关使用Thymeleaf设置属性值的更多信息,您可以查看their documentation

以下是有关处理器和方言的Broadleaf和Thymeleaf文档的链接: