How to read external resources in Velocity

I would like to read {key:value} pairs in Velocity templates (for user macros). These values are placed in an external resource file.

Is this possible?

Thank you,

1 answer

1 accepted

Access to physical files would be a security risk and can't be done directly, Two options:

a) you could do this using a different approach, though a Beanshell (part of bobs Scripting plugin) that could load resources and generate markup. Some scripting/Dev skills required.

b) IIRC you can write a plugin that contributes the necessary resources as part of a plugin, with a Java accessor object written to read the data, that object could then be made available in the velocity context. Dev skills required.

I think b) is the way to go, is there any URL that document this approach?

Thank you.

You'll need to create a plugin with a Velocity Context Module, that bundles the 'helper' you access from Velocity, along with the resources that may be packaged within the plugin or on your local OS if thats what you wanted to do.


Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

356 views 20 10
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