1 Basic Usage
- Add a Velocity part. Do not hide it.
- Add any HTML part, set “template” as the key and hide it
2 Defining Macros
There are three possible ways to define macros:
2.1 Inline Macros in Templates
Define the macro directly in the template, which will use it. The drawback of this approach is, that macros can not be reused in other tags in a proper manner.
Note: Starting with Gentics Content.Node 5.2.5, inline macros will only be callable in the template and not interfere with macros from other tags.
2.2 Global Macro Library
For correctly reusing macros, they must be defined in a global macro library.
$VELOCITY_PROPERTIES["resource.loader"] = "string,file"; $VELOCITY_PROPERTIES["file.resource.loader.path"] = "/Node/etc/"; $VELOCITY_PROPERTIES["file.resource.loader.cache"] = "true"; $VELOCITY_PROPERTIES["file.resource.loader.modificationCheckInterval"] = "60"; $VELOCITY_PROPERTIES["velocimacro.library"] = "velocimacro-lib.vm";
You define a single file /Node/etc/velocimacro-lib.vm
(which should be readable for user node) to contain the global macros. Those macros will automatically be available to all Velocity Tags. With the above settings, changes to the velocimacro-lib.vm
will be available after up to 60 seconds.
After changing the /Node/etc/node.conf file
, the Tomcat must be restarted in order for the setting to take effect.
See the Velocity Developer Guide for details about the velocity configuration settings.
2.3 Macro Library in a pagetag
The third possibility to reuse macros is to create e.g. a special page, that contains the macros in a tag. Then add a third tagpart with keyword “macros” and parttype “Tag (page)” to the Velocity Tag, and let it link to the tag of the macro library page. In this way, the macros can be maintained in a global place, but will be used as inline macros in the tags.