spring-boot - 如何使用 Spring Boot 和 Mustache 实现布局模板

标签 spring-boot mustache

我有一个使用 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/

相关文章:

hibernate - Spring Boot 中的多个 SQL 导入文件

spring-boot - 执行完第一个作业后运行第二个批处理作业 Spring boot

java - 由于响应内容类型无效,其余模板交换失败

java - Gradle , Kotlin : How to add another spring boot project as a module dependency in intellij

带 mustache 的 Controller 未接收到 Spring 表单数据

javascript - Moustache.js 中的列表和来自 mongodb 的 bson 数据

javascript - Mustache.js 对象 #<Document> 没有方法 'search'

java - 使用 Spring-Boot 和 Jetty 设置 SSL

handlebars.js - 将变量附加到 Handlebars 中的部分名称( mustache )

PHP - 循环中的 mustache 部分