Fórumok

How to set environment variable and read it using .vm

thumbnail
Dmitry Brin, módosítva 13 év-val korábban

How to set environment variable and read it using .vm

New Member Bejegyzések: 24 Csatlakozás dátuma: 2010.06.29. Legújabb bejegyzések
Hi,
I am looking for a simple way to set an environment variable at portal instance level (set it once) and read it in using VM template (init.vm actually) I don't want to use URL mappings as those can change.

Thanks for any suggestions,
Dmitry.
thumbnail
Tina Agrawal, módosítva 13 év-val korábban

RE: How to set environment variable and read it using .vm

Expert Bejegyzések: 297 Csatlakozás dátuma: 2008.01.03. Legújabb bejegyzések
Hi,

This link might help you - Custom Velocity Variables

To check existing variables refer to class VelocityVariables.java

Regards,
Tina
thumbnail
Dmitry Brin, módosítva 13 év-val korábban

RE: How to set environment variable and read it using .vm

New Member Bejegyzések: 24 Csatlakozás dátuma: 2010.06.29. Legújabb bejegyzések
Thanks for the suggestion. Isn't there a way to read it from a properties file like ext-portal.properties using propUtil?
thumbnail
Tina Agrawal, módosítva 13 év-val korábban

RE: How to set environment variable and read it using .vm (Válasz)

Expert Bejegyzések: 297 Csatlakozás dátuma: 2008.01.03. Legújabb bejegyzések
You can use propsUtil to read from properties file in VM.
Something like this - $propsUtil.get("keyName").

Refer to the link - Access Object from a Velocity Template

Regards,
Tina
thumbnail
Dmitry Brin, módosítva 13 év-val korábban

RE: How to set environment variable and read it using .vm

New Member Bejegyzések: 24 Csatlakozás dátuma: 2010.06.29. Legújabb bejegyzések
Tina, I was able to use you suggestion. Here is what I had to do:

on the portal_normal.vm I added
$propsUtil.get("my.special.url")
to source the property stored in myspecial.properties file.

In order for Liferay to read my properties file I added this line
include-and-override=portal-instance.properties, myspecial.properties
to the portal-ext.properties .

This allows me to add and read properties at the portal level without modifying the install.
Himanshu Modi, módosítva 12 év-val korábban

RE: How to set environment variable and read it using .vm

New Member Bejegyzések: 13 Csatlakozás dátuma: 2011.07.27. Legújabb bejegyzések
Hi Tina and all,

Thank you all for useful information.
But please let me know how to implement the scenario like-
I want to create a properties file (say test.properties) inside theme plugin and define variables inside it.
so how to read this properties file in vm template file?
and in which folder should I create this properties file?

Thanks,
Himanshu
Ludovic Dussart, módosítva 10 év-val korábban

RE: How to set environment variable and read it using .vm

New Member Bejegyzések: 8 Csatlakozás dátuma: 2013.02.25. Legújabb bejegyzések
Dmitry Brin:
Tina, I was able to use you suggestion. Here is what I had to do:

on the portal_normal.vm I added
$propsUtil.get("my.special.url")
to source the property stored in myspecial.properties file.

In order for Liferay to read my properties file I added this line
include-and-override=portal-instance.properties, myspecial.properties
to the portal-ext.properties .

This allows me to add and read properties at the portal level without modifying the install.



Hi Dmitry,

It's look to me that $propsUtil.get("xxx") only read the properties declared in portal-ext.properties :/
I try to use this mecanism but it doesn't work ..

If i try to call $propsUtil.get("my.special.url") only present in myspecial.properties, liferay displaying $propsUtil.get("my.special.url") but when i write my.special.url property in portal-ext, $propsUtil.get("my.special.url") displaying the right value ..