2017-07-19 28 views
0

http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#template-layout文檔說:爲什麼th:自從Thymeleaf 3.0以後不再推薦使用include?

上面的代碼定義了一個片段稱爲複製,我們可以在我們的主頁使用日的一個輕鬆包括:插入或日:更換屬性(還TH:包括,但其使用不再推薦,因爲Thymeleaf 3.0)。

我個人發現th:insert實現模板的唯一可能方式。

那麼這是什麼意思? th:insert已被棄用或將來會被刪除?或者這是不好的做法?

是什麼使th:insert聲譽不好?

回答

1

我認爲這是要概括什麼是以前th:include提供的情況...

Thymeleaf 3.0引入了一種新類型的表達式作爲 一般Thymeleaf標準表達系統的一部分:片段的表達。

它們看起來像這樣:〜{commons :: footer}並且是的,它們非常類似於可以在th中使用的語法:replace和 th:include(now th:insert)因爲它們確實使用了 這種語法,但是它的通用性使它現在可以在其他 範圍內使用。

請參閱Fragment Expressions

Thymeleaf文檔中沒有任何內容暗示不應該使用th:include,也不建議th:include將在未來版本中刪除。

0

https://github.com/thymeleaf/thymeleaf/issues/625我得到響應,與AttoParser V2.0.3開始和對應Thymeleaf v3.0.4 content()選擇器可以被使用,其與th:replace使得th:include冗餘:

<div th:replace="thymeleaf/layout :: tmpl(~{::body/content()})"> 
    XXX 
</div> 
相關問題