简体   繁体   English

带有 Freemarker 的模板 inheritance

[英]Templates inheritance with Freemarker

I'm starting a new progect usign Freemarker as server-side template engine.我正在开始一个新的项目,使用 Freemarker 作为服务器端模板引擎。

I often use Thymeleaf in my web project, adding Layout Dialect to create a hierarchy of template: starting from a main layout and decorating it with specific section for every page needed in my project.我经常在我的 web 项目中使用 Thymeleaf,添加布局方言以创建模板层次结构:从主布局开始,并为我的项目中需要的每个页面使用特定部分进行装饰

I haven't used Freemarker very often, but, if I'm not wrong, it only implements templating by include / import .我没有经常使用 Freemarker,但是,如果我没记错的话,它只通过include / import实现模板。

Is there a way to use something like Thymeleaf Layout Dialect also with Freemarker?有没有办法在 Freemarker 中使用 Thymeleaf 布局方言之类的东西?

In an old project I used Apache Tiles to do something similar, but now the project is retired.在一个旧项目中,我使用 Apache Tiles 来做类似的事情,但现在该项目已退役。 Is there any recent alternative?最近有替代方案吗?

There's no "inheritance" like in some other template engines.没有像其他模板引擎那样的“继承”。 The main way of reusing pieces is with #macro (and #nested ) in FreeMarker.重用片段的主要方式是在 FreeMarker 中使用#macro (和#nested )。 Also note that macros are first class values, so they can be passed to other macros as arguments.另请注意,宏首先是 class 值,因此它们可以作为 arguments 传递给其他宏。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM