Page History
...
Magnolia CMS为FreeMarker和JSP提供可立即使用的绘制器。您可以选择偏好的语言,甚至可以在相同的网站上混合使用,在一些模板里使用FreeMarker而另一些里用JSP。
...
FreeMarker
在Magnolia里,我们更倾向于使用Freemarker,因其灵活性,较清晰的语法,更好的错误报告机制,也因为它不依赖于文件系统。模板不需要导出到文件系统,这意味着您可以将它们存储在内容库中,并像其他资源一样获得,随意添加版本控制,以及添加定制的属性和元数据。在Magnolia里,我们更倾向于使用FreeMarker,因其灵活性,较清晰的语法,更好的错误报告机制,也因为它不依赖于文件系统。模板不需要导出到文件系统,这意味着您可以将它们存储在内容库中,并像其他资源一样获得,随意添加版本控制,以及添加定制的属性和元数据。
样例:绘制页面标题,如果没有标题则绘制名字。
Code Block |
---|
<h3>${content.title!content.@name}</h3> |
这是Freemarker提供的一些好处:这是FreeMarker提供的一些好处:
- 它是一种通用的模板语言,不束缚于Java环境。
- 提供基本的指令,如
[if]
,[else]和
[list]
。 - 有一大套built-ins。
- 可以调用任何Java对象和返回对象的公共方法。
- 不需要在请求/回复环境中绘制。
- 提供直接获取节点对象(beans)的方法。
- 可直接迭代任何扩展一个Java列表的内容集合。
- 严格的null值处理导致稳定的模板。
- 需要的话允许使用JSP标签库。
...
Advanced Tables - Table Plus | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||
|
The STK defines its own renderer STKRenderer
configured in the Configuration app > STK定义它自己的绘制器STKRenderer
,在Configuration应用 > /modules/standard-templating kit/rendering/renderers/stk
.里配置。
Advanced Tables - Table Plus | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||
|
The renderType
property in page, area and component definitions defines the template renderer to use. For STK templates the type is stk
.
Loading scripts
The system can load Freemarker scripts from three places in this order:
页面, 区域和组件定义里的renderType
属性定义使用的模板绘制器。对STK模板来说,类型是stk
。
加载脚本
系统可以从三个地方加载FreeMarker脚本,以下列顺序:
- 网络应用程序的文件系统。您可以将脚本文件放在
/<CATALINA_
Filesystem of the webapp. You can place a script file in/<CATALINA_HOME>/webapps/<contextPath>/templates
folder.文件夹。 templates
workspace. The template needs to be enabled to be considered.- Web application's classpath. This is where default STK templates are located. Best practice is to package scripts inside the module JAR. A module JAR resides in the classpath so the system finds it.
Template loaders
- 工作区。模板需被使能才能被考虑进去。
- 网络应用程序的类路径(classpath)。这是STK模板默认存放的地方。最佳实践是在模块JAR里打包脚本。模块JAR在类路径里好让系统找得到它。
模板加载器
FreeMarker模板加载器在Configuration应用的Freemarker template loaders are configured in the Configuration app > /server/rendering/freemarker/jcr
and 和/webapp
:
LazyWebappTemplateLoader
loads templates from the webapp folder by default. If no matching template is found it will be loaded from the classpath.JcrRepoTemplateLoader
allows template loading from the repository. This loader is included in the In-place Templating module.LazyFileTemplateLoader
allows loading of templates from an arbitrary location on the file system.
里配置:
LazyWebappTemplateLoader
默认从webapp文件夹里加载模板。如果没找到匹配的模板,则将会从类路径中加载。JcrRepoTemplateLoader
允许从内容库中加载模板。加载器包含在In-place Templating模块。LazyFileTemplateLoader
允许从文件系统的专有位置中加载模板。
需要的话您也可以写下您自己定制的模板加载器。You can also write your own custom template loader if needed.
Advanced Tables - Table Plus | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||||||||||||||||||||
|
Tip |
---|
JSP scripts can only reside on the file system because they require pre-compiling by the server before they can be rendered. JSP scripts are extracted onto the file system during module installation or update |
JSP脚本只能存在于文件系统中,因为它们在被绘制前需要服务器预编译。JSP脚本在模块安装或更新时被解压到文件系统。 |
编辑脚本
Panel | ||||||
---|---|---|---|---|---|---|
| ||||||
|
...