我有一个使用 Mustache 模板引擎从 Spring Initlializer 创建的 Sprint Boot Web Maven 项目。
到目前为止,它的工作原理是,我可以做基本的事情,但我想设置一个布局(模板),其中包含 html 的主体,例如<html>...</html>
而我的 View 模板将仅包含页面内容,例如<h1>Hello World</h1>
我可以让部分工作,这样我就可以做 {{>header}}<h1>Hello World</h1>{{>footer}}
我想要做的是:
index.html
{{>header}}{{>content}}{{>footer}}
home.html
<h1>Hello World</h1>
我找不到任何教程或文档来说明如何执行此操作。
最佳答案
如果有帮助,我在这里找到了一些引用文档:
https://spring.io/blog/2016/11/21/the-joy-of-mustache-server-side-templates-for-the-jvm
请参阅自然模板部分。
{{!
<!doctype html>
<html lang="en">
<body>
}}
{{>header}}
<h1>Demo</h1>
<div>Hello World</div>
{{>footer}}
{{!
</body>
</html>
}}
关于spring-boot - 如何使用 Spring Boot 和 Mustache 实现布局模板,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34449906/