Freemarker - Environment Variables

Hi all, anyway to get an environment variable in the Freemarker templates?

Thanks
J

You add variables in the components that render the page.

You could check if ${environment.VAR_NAME} works ( I don’t know if environment map is populated by default…)

Yup we can do that, however not all of our pages are rendered using components, and we have a central FTL we want to use for images.

so that does not work as it does not know what environment is
how do I import the map?

You should be able to attach a component to any ftl. How are you populating the image template?

Hi, not got a problem attaching a component to an FTL, we have a lot of components. All I want to do is read an environment variable in the FTL, will save a lot of coding and changes. We have one FTL for rendering the image html

What do you mean by environment variable? What environment and why would that variable be available in any ftl?

my assumption was “system” variables (jvm variables and variables passed through JVM paramaters).

Those are only set (passed through) if implementation (framework) passes them through environment object during template processing, and it looks like we don’t do that …

I don’t think freemarker passes jvm environment by default to the template. You would still have to set that to the freemarker environment. We wouldn’t do that by default either. That can be a security risk.

Creating a component to set a variable is the only way I can think to achieve this.

okay no worries

If you need an environment variable, you can add this variable to a properties files. Then create a common component class, in that class, get the environment variable from the properties file.

All business components can extend from the common component class. Then you can use it in ftl files.

Ok thanks.