2016-09-08 24 views
0

我的問題如下: 在此代碼在BLC標籤Thymeleaf個標籤

<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]}"是不合適的,因爲它是從thymeleaf標籤庫。任何想法如何在blc:menu標籤中獲得此值?

回答

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

通過以下鏈接可在處理器和方言的闊葉和Thymeleaf文檔:

+1

- 闊葉樹:http://www.broadleafcommerce.com/docs/core/current /闊葉概念/表示層#thymeleaf – ProfEidarios