Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. main脚本包含一个cms.init指令,嵌入了编写实例上所需的CSS和JavaScript。
  2. cms.area指令调用即将绘制的区域。该指令通过名字来辨别区域,在此例中为extras。如果该区域有子区域,您需要一个分开的脚本来调用要绘制的子区域。然后,如果该区域只包含组件,那么您不需要区域脚本。
  3. 页面的脚注同样使用cms.area指令来绘制。该区域不含子区域,只有组件。

添加您自己的指令

You can add your own directives. They make Java methods and functions in your own classes available to template scripts:

您可以添加自己的指令。以下步骤使您类中的Java方法和功能对模板脚本可用:

  1. 像通常一样写作和编译您的Java类。
  2. 拷贝这个类文件到您的Magnolia网络应用的
  3. Write and compile your Java class as you normally would.
  4. Copy the class file to WEB-INF/classes folder of your Magnolia web application.文件夹。
  5. 转到Configuration应用Go to the Configuration app > /modules/rendering/renderers/freemarker/contextAttributes.
  6. Under /contextAttributes, create a content node such as myClass. Name it after the purpose of your class.
  7. Under myClass, create two data nodes:
  8. 下,创建一个内容节点,如myClass。用您类的用途命名它。
  9. myClass里,创建两个数据节点:
    • componentClass,设置其值为您放在componentClass and set its value to the fully-qualified name of the class you placed in WEB-INF/classes.里的类的完全相称类名。
    • name and set the value to myClass.,设置其值为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.

...