How2 use built in velocity context?

Hi,

I'm using a velocity template rendered by the velocity template renderer from within a servlet. The template is rendered fine although my web-resources are bound like they should.

Problem is I cant get any of the built in velocity context elements like $dateutils, $generalUtil, $baseUrl and so on to do anything. Everything is rendered as string and seems not being processed as variables.

As those contexts are mentioned to be accessible from action- and macro-modules, I already tried to implement GeneralUtil as a velocity-context-item like that:

<velocity-context-item key="generalUtilContextItem"
	name="General Util Context Item" context-key="generalUtil"
	class="com.atlassian.confluence.util.GeneralUtil"
/>

But with no effort. Did I miss anything or is it just impossible to get them to work in a servlet-hooked template?

Edit:

Thanks for your fast reply John and sorry for my delayed response :(

I followed Your suggestion and installed a lokal confluence instance via the atlassian plugins sdk 3.2.

Then I'd set up a new servlet-plugin project to run under Confluence 4.3. I am now able to use the applicationProperties Context just as suggested, but unfortunatly I still can't use the generalUtils or dateUtils items. Do I have to set up a manager instance in my servlet to be able to use them or should it be enough to declare them as velocity-context-item or template-context-items in the atlassian-plugin.xml?

Thanks and regards

Artee

1 answer

Hi Artee,


I see that this question relates to an OnDemand instance of Confluence, and if that is the case then the reason you won't be able to do this is because this is a restricted function in OnDemand, as per our documentation on the restricted functions in OnDemand: https://confluence.atlassian.com/display/AOD/Restricted+Functions+in+Atlassian+OnDemand

Therefore if this functionality is important to you then you should consider hosting your own instance of Confluence so that you can customise the velocity templates in your instance.

All the best,
John

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Posted Jul 10, 2018 in Confluence

We want to see the templates you've created in Confluence!

Hi Community, Jessica here from the Confluence Product Marketing team!  July’s community challenge is all about sharing pictures  — and as an extension of our first post on what ...

864 views 23 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you