有沒有使用Thymeleaf製作複合組件(比如在JSF中)的方法?我發現如何將參數發送到可以使用表達式語言檢索的片段。但我還沒有想出如何發送標記碎片,就像你可以在JSF中。百里香複合組件
例如,我有幾個頁面在左邊有非常相似的菜單。我希望能夠在我的所有頁面上使用單個片段,但會傳遞一些標記以顯示在菜單底部。有些頁面必須在底部顯示文本,有些頁面必須顯示文本,例如,它實際上比這更復雜。
<div class="menu" th:frament="menu">
<a th:text="${menuItem1}"></a>
<a th:text="${menuItem2}"></a>
<a th:text="${menuItem3}"></a>
<markup sent as parameter /> <!-- how do I do this? -->
</div>
<div th:substitueBy="template :: menu" th:with="menuItem1=item1, menuItem2:item2, menuItem3:item3">
<markup to be sent as parameter /> <!-- this does not work -->
</div>
遲了幾年,但謝謝!不幸的是,我不再使用百里香,所以我無法測試你的圖書館 – Hoffmann
是的,它已經很晚了。但對於也在尋找這個問題的人來說,答案可能會有所幫助。 – Serbroda