Reputation: 32111
I tried adding a bunch of #set($x=abc)
statements in the VM_global_library.vm file, but these variables aren't available in my VM templates.
I'd like to set a single global variable for things like the base path to images and such. Is this possible?
Upvotes: 2
Views: 6025
Reputation: 6943
It's easy to set up and manage global data if you create your Context with VelocityTools.
Upvotes: 1
Reputation: 4063
Your VM_global_library.vm
should only contain Velocity macros, I suspect any variables declared outside of a macro are just ignored.
You could create a separate .vm
file that holds all of your globals, and then make sure you #parse
it in every template where you need them (or you could write some code to automatically parse it). I've previously extended the VelocityLayoutServlet
for example to do something similar: merge my "global-variables.vm
" first to add them to the Context, and then carry on and render the view.
If your globals are just simple strings it would probably be more efficient to put them in a properties file and have your code push them directly into the VelocityContext
.
Upvotes: 1
Reputation: 12785
You can add that variable to the VelocityContext and then it will be available to everyone and will act as a Global Variable.
Upvotes: 2