Page History
...
main
脚本包含一个cms.init
指令,嵌入了编写实例上所需的CSS和JavaScript。cms.area
指令调用即将绘制的区域。该指令通过名字来辨别区域,在此例中为extras
。如果该区域有子区域,您需要一个分开的脚本来调用要绘制的子区域。然后,如果该区域只包含组件,那么您不需要区域脚本。- 页面的脚注同样使用
cms.area
指令来绘制。该区域不含子区域,只有组件。
添加您自己的指令
You can add your own directives. They make Java methods and functions in your own classes available to template scripts:
您可以添加自己的指令。以下步骤使您类中的Java方法和功能对模板脚本可用:
- 像通常一样写作和编译您的Java类。
- 拷贝这个类文件到您的Magnolia网络应用的
- Write and compile your Java class as you normally would.
- Copy the class file to
WEB-INF/classes
folder of your Magnolia web application.文件夹。 - 转到Configuration应用Go to the Configuration app >
/modules/rendering/renderers/freemarker/contextAttributes
.。 - Under 在
/contextAttributes
, create a content node such asmyClass
. Name it after the purpose of your class. - Under
myClass
, create two data nodes: - 下,创建一个内容节点,如
myClass
。用您类的用途命名它。 - 在
myClass
里,创建两个数据节点: componentClass
,设置其值为您放在componentClass
and set its value to the fully-qualified name of the class you placed inWEB-INF/classes
.里的类的完全相称类名。name
and set the value tomyClass
.,设置其值为myClass
。
这就让您能够使用This allows you to access all the static methods in myClass
from templates using the ${myClass.myMethod()
} Freemarker syntax.
...
FreeMarker句法,从模板获得myClass
里所有的静态方法。
模板功能
TemplatingFunctions
includes useful methods that you can use in your templates. The methods are exposed as cmsfn
. The decode
method that removes escaping of HTML on properties is is an example and the snippet below shows its use in the stkTextImage
component script.
...