用Thymeleaf扩展视图 [英] Extend A View With Thymeleaf
本文介绍了用Thymeleaf扩展视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以扩展与百里香的共享视图?
is it possible extend a shared view with thymeleaf?
我发现可以使用 帧 ,但这不是我想要的. 相反,我想要一个类似于.NET MVC的东西,比如 @RenderBody(),另一个需要通过包含共享视图来扩展共享视图的视图.
I saw that is possible use framents but is not what I want. Instead I want something similar to .NET MVC, with something like @RenderBody() and another view that extend the shared view by including the shared view.
推荐答案
您可以使用胸腺目布局方言扩展视图.
布局页面
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
...
<body layout:fragment="body">
...
</body>
</html>
内容页面
在内容页面中,您使用layout:decorator
属性引用布局(装饰器)页面.
In your content page, you refer to the layout (decorator) page using the layout:decorator
attribute.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="layout.html">
...
<body layout:fragment="body">
<p>Actual page content</p>
</body>
</html>
一页中可能有多个片段.
It is possible to have multiple fragments in one page.
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout">
...
<body>
<div layout:fragment="content"></div>
<footer layout:fragment="footer"></footer>
</body>
</html>
这篇关于用Thymeleaf扩展视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文