Confluence has a few distinct Velocity contexts for different purposes in the application (user macros, email templates, and exports), but the most commonly used context is called the "default context".
To detect deprecation and code change breakages during compilation time, it is recommended that, where possible, you add functionality that calls Confluence code in your plugin Java code (that is, actions or components) rather than in a Velocity template. You can call any method on your plugin action from Velocity with instead of putting complicated logic in your Velocity template that is not checked by the compiler.
For example, if your plugin needs a calculated list of particular pages to display in the Velocity template, you should do the following:
Although it is currently supported, you should not perform data updates directly from Velocity code, and future versions of Confluence may prevent you doing this in your plugin.
The following list highlights the most important entries in the default Velocity context. You can get a full list by calling MacroUtils.defaultVelocityContext(). The default Velocity context is used for templates rendered by:
The current WebWork action
Your action class, normally a subclass of ConfluenceActionSupport
should be used for plugin internationalization.
Class Reference: I18NBean
Provides a date and time formatter suitable for the exporting user's locale and environment.
Class Reference: DateFormatter
The current servlet request object (if available)
Class Reference: >HttpServletRequest
The current context path. Used for creating relative URLs:
Class Reference: String
The current servlet response object (should not be accessed in Velocity)
Class Reference: HttpServletResponse
Can retrieve the current global settings with
Class Reference: SettingsManager
The base URL of the Confluence installation. Used for creating absolute URLs in email and RSS:
Class Reference: String
A object, with useful utility methods for URL encoding etcSeveral methods are deprecated. Use .
Class Reference: GeneralUtil
|Provides methods for URL encoding|
Class Reference: htmlUtil
The currently authenticated user, or if anonymous user.
Class Reference: ConfluenceActionSupport
For retrieving users, groups and checking membership
Class Reference: UserAccessor
Can be used to check permissions, but it is recommended that you check permission in your action
Class Reference: PermissionHelper
Class Reference: AttachmentManager
Class Reference: SpaceManager
Class Reference: PageManager
User macros have a Velocity context, which includes all the above items and some additional entries specific to user macros. See Guide to user macro templates for a list of the latter.
When you customise the Velocity templates for Confluence email notifications, you can use the following items in addition to the default context.
Default stylesheet CSS contents
Same as in the default context
The email notification subject
Wiki rendering support
Notification render context for use with
Daily report (only for digest notifications)
Whether this notification should include diffs
Whether this notification should include full page content
Diff rendering support
Diff for the notification, if enabled
The export context does not include any of the values from the default context. See Available Velocity contexts in exporters for a complete list.