Cms Macros

From OpenCms Wiki
(Difference between revisions)
Jump to: navigation, search
m
 
(6 intermediate revisions by one user not shown)
Line 1: Line 1:
Using Cms Macros
 
 
 
OpenCms has a macro language that you can use parameters to your jsp tags.  This is particularly useful for cms:contentload.
 
OpenCms has a macro language that you can use parameters to your jsp tags.  This is particularly useful for cms:contentload.
  
 
The macros are resolved using CmsMacroResolver.  This "resolves macros in the form of ${key} in an input String.  The macro names that can be resolved depend of the context objects provided to the resolver using the set... methods."
 
The macros are resolved using CmsMacroResolver.  This "resolves macros in the form of ${key} in an input String.  The macro names that can be resolved depend of the context objects provided to the resolver using the set... methods."
  
Some examples:
+
The old macro delimeter is $.  The new one is %, as of 7.0
*${*} - resolves to any file
+
  
You can also use build in cms macros, such as:
+
If a macro is found that can not be mapped to a value by the given macro resolver, it is left untouched in the input.
 +
 
 +
== Key examples ==
 
*${property.collector} - resolves to a property called collector
 
*${property.collector} - resolves to a property called collector
 
*${number} - resolves to any number
 
*${number} - resolves to any number
 
*${property.xml-content} -
 
*${property.xml-content} -
    Will be replaced by the value of the property "xml-content"
+
Will be replaced by the value of the property "xml-content"
 
*${opencms.uri}  -
 
*${opencms.uri}  -
    Will be replaced by the current OpenCms VFS URI. Its typical to use this with the singleFile collector a detail view jsp.
+
Will be replaced by the current OpenCms VFS URI. Its typical to use this with the singleFile collector a detail view jsp.
 
*${opencms.filename} -
 
*${opencms.filename} -
    Will be replaced by the resource name of the current xml content resource while looping through the single resources.
+
Will be replaced by the resource name of the current xml content resource while looping through the single resources.
 
*${param.resourceType} -
 
*${param.resourceType} -
    Will be replaced by the value of the Http reuest parameter "resourceType.
+
Will be replaced by the value of the Http reuest parameter "resourceType.
 +
 
 +
 
 +
A full list of macro Keys is at [http://www.opencms.org/export/javadoc/core/org/opencms/util/CmsMacroResolver.html].
 +
 
 +
== Other values ==
 +
You can pass in other values, too, that will be left alone and passed on to the Cms Resource Collector.
 +
 
 +
Examples:
 +
*${*}.{*} - resolves to any file with an extension
 +
 
 +
 
 +
[[Category:Developing in OpenCms ]]

Latest revision as of 17:55, 4 July 2011

OpenCms has a macro language that you can use parameters to your jsp tags. This is particularly useful for cms:contentload.

The macros are resolved using CmsMacroResolver. This "resolves macros in the form of ${key} in an input String. The macro names that can be resolved depend of the context objects provided to the resolver using the set... methods."

The old macro delimeter is $. The new one is %, as of 7.0

If a macro is found that can not be mapped to a value by the given macro resolver, it is left untouched in the input.

Key examples

  • ${property.collector} - resolves to a property called collector
  • ${number} - resolves to any number
  • ${property.xml-content} -

Will be replaced by the value of the property "xml-content"

  • ${opencms.uri} -

Will be replaced by the current OpenCms VFS URI. Its typical to use this with the singleFile collector a detail view jsp.

  • ${opencms.filename} -

Will be replaced by the resource name of the current xml content resource while looping through the single resources.

  • ${param.resourceType} -

Will be replaced by the value of the Http reuest parameter "resourceType.


A full list of macro Keys is at [1].

Other values

You can pass in other values, too, that will be left alone and passed on to the Cms Resource Collector.

Examples:

  • ${*}.{*} - resolves to any file with an extension
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox