About
If you have ever worked with JIRA before, content and template renderings are mostly handled by the VelocityManager class. To know what are the parameters available in the context, you can grab the $ctx (java.util.Map) from it.
However, in Confluence, they do not provide any self referencing parameters in the context, therefore you may need to modify the source code in order to find out what are lurking in it.
But.. which class(es)?
 | Too lazy to read the entire content?
Click these:
|
Velocity in Confluence
There are a few classes used in Confluence to render the content, the one which you want to look into is:
| com.atlassian.confluence.util.velocity.VelocityUtils |
There may be some which I have missed out (and also the interesting ApplyDecoratorDirective class), perhaps you would like to take a look at the See also section.
Adding self-referencing object
To add a self-reference, you need to identify the context variable then inject it into the source code.
com.atlassian.confluence.util.velocity.VelocityUtils
The VelocityUtils has two methods used for rendering:
- public static String getRenderedTemplateWithoutSwallowingErrors(String templateName, Context context)
- public static String getRenderedContent(String templateContent, Map contextMap)
getRenderedTemplateWithoutSwallowingErrors
This method, as far as I know, is used to render the Confluence templates – SiteMesh decorators. The context is a com.opensymphony.webwork.views.velocity.WebWorkVelocityContext object. Therefore, to display all the parameters in it, you can use:
<pre>
#foreach($p in $ctx.getKeys())
$p.toString() - $ctx.get($p).getClass().getName().toString()
#end
</pre>
Ops?
The same Velocity code, if exists in the page.vmd decorator, produces this result:
getRenderedContent
This method, again AFAIK, is used to render the macros, user macros, and other plugins. The context is a java.util.Map. Therefore, to display all the parameters in it, you can use:
<pre>
#foreach($p in $ctx.keySet().toArray())
$p.toString() - $ctx.get($p).getClass().getName().toString()
#end
</pre>
See also
Please also take a look at:
| com.atlassian.confluence.mail.MacroUtils.defaultVelocityContext() |
List of default parameters used by macro |
| com.atlassian.confluence.mail.VelocityRenderedQueueItem |
|
| com.atlassian.confluence.plugin.descriptor.web.AbstractWebBean |
Adds com.atlassian.confluence.themes.PageHelper and used by WebLabel and WebLink |
| com.atlassian.confluence.servlet.ConfluenceVelocityServlet |
|
| com.atlassian.confluence.setup.velocity.ApplyDecoratorDirective |
Used to apply SiteMesh decorator |
| com.atlassian.confluence.setup.webwork.ConfluenceVelocityContext |
A custom velocity context to return things to use in Velocity templates |
| com.opensymphony.webwork.views.velocity.VelocityManager |
Webwork's VelocityManager |