模板继承与Freemarker

huangapple go评论65阅读模式
英文:

Templates inheritance with Freemarker

问题

我正在使用Freemarker作为服务器端模板引擎开始一个新的项目。

在我的Web项目中,我经常使用Thymeleaf,添加Layout Dialect来创建模板的层次结构:从主要布局开始,然后为项目中需要的每个页面添加特定的部分。

我很少使用Freemarker,但如果我没记错的话,它只通过include/import来实现模板化。

有没有办法在Freemarker中使用类似于Thymeleaf Layout Dialect的东西?

在以前的项目中,我使用了Apache Tiles来实现类似的功能,但现在该项目已经不再维护了。有没有最近的替代方案?

英文:

I'm starting a new progect usign Freemarker as server-side template engine.

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.

I haven't used Freemarker very often, but, if I'm not wrong, it only implements templating by include/import.

Is there a way to use something like Thymeleaf Layout Dialect also with Freemarker?

In an old project I used Apache Tiles to do something similar, but now the project is retired. Is there any recent alternative?

答案1

得分: 1

没有像其他一些模板引擎中的 "继承"。在 FreeMarker 中,重用代码片段的主要方式是使用 #macro(以及 #nested)。还要注意,宏是一级值,因此可以将它们作为参数传递给其他宏。

英文:

There's no "inheritance" like in some other template engines. The main way of reusing pieces is with #macro (and #nested) in FreeMarker. Also note that macros are first class values, so they can be passed to other macros as arguments.

huangapple
  • 本文由 发表于 2020年7月22日 12:31:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/63026920.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定