#global for using variables across multiple custom content modules
Hi all,
Wondering if any one has done this before or come knows off a better way to do it.
I need to grab an assigned variable from one custom content to use in another.
I know in freemarker #assign means the variable is scoped only to that template. However I thought #global should allow access in all templates. This does not seem to be the case on our lithium pages it just throws the normal error, if the variable is referenced from a different custom content that it was initilised in.
IE
In custom content1 I am putting
<#assign navTitle1="Competition" />
And in custom content2 i am putting
${navTitle1}
Which is throwing an error, any help would be great
Cheers
Dom
Unfortunately I don't think the global directive is going to work in that way since the templates are being evaluated independently in the example you gave. If you want to "share" variables across components, you could consider making a "common" component and then use the include directive or import directive to pull that into each custom component that you want to access the "common" variables for. Here's more info on that:
http://freemarker.sourceforge.net/docs/ref_directive_include.html
http://freemarker.sourceforge.net/docs/ref_directive_import.html
For example, you could create a component named "global_vars" and then in the other components, use:
<#include "global_vars" />
One other idea you might want to explore is the use of parameters with components: