掲示板

Best way to share variable across multiple themes

12年前 に Jesse Paria によって更新されました。

Best way to share variable across multiple themes

Junior Member 投稿: 69 参加年月日: 11/03/04 最新の投稿
I have several themes I am managing and there are a couple of variables that could be shard across all the themes.

I am trying to figure out the most efficient way to do this. I want to share the variables as to make it easer to maintain all the themes.

My plan was to have a separate webapp that would hold a standalone vm template in it. This template would hold the variables and all the themes would load this template from the init.vm file. Evidently, velocity won't allow parsing outside the template root without portal-wide customization, which I can't do.

The other option is to use the velocity resource loader. Which seems tedious and I am not even sure if this works within Liferay 5.2. Any thoughts on this?

I could load a text file with Java IO and build the variables from this but this also doesn't seem to be an efficient method.

Does anyone have any suggestions? I would love to hear ideas and feedback.

Thanks
thumbnail
12年前 に Sagar A Vyas によって更新されました。

RE: Best way to share variable across multiple themes

Liferay Master 投稿: 679 参加年月日: 09/04/17 最新の投稿
Hi Jesse,

If you have observed $themeDisplay,$portletDisplay,$fullTemplatesPath, etc variable are available in any theme vm file.

These variable are coming from init.vm of \html\themes\_unstyled\template\init.vm.

I guess you need something like this only, if any how you can find out how this init.vm is accessible to every theme then might you will get answer of your question emoticon

Even i would like to same.

where all these variable are created $themeDisplay,$portletDisplay,$fullTemplatesPath, and how can we insert our own variable in same.

Thanks,
Sagar Vyas
12年前 に Jesse Paria によって更新されました。

RE: Best way to share variable across multiple themes

Junior Member 投稿: 69 参加年月日: 11/03/04 最新の投稿
Yes thank for replying.

Yes I realize I have all those built-in variables available but as you said, I am trying to create custom variables that I can share across multiple themes.

Another option I totally overlooked is creating a custom variable with a hook. This seems like a bit of work for a couple of variables but perhaps that is the best method.

Thanks
thumbnail
12年前 に Sagar A Vyas によって更新されました。

RE: Best way to share variable across multiple themes

Liferay Master 投稿: 679 参加年月日: 09/04/17 最新の投稿
Hi Jesse,

Yes I realize I have all those built-in variables available but as you said, I am trying to create custom variables that I can share across multiple themes.


I would prefer this way emoticon

Thanks,
Sagar Vyas
thumbnail
12年前 に Sandeep Nair によって更新されました。

RE: Best way to share variable across multiple themes (回答)

Liferay Legend 投稿: 1744 参加年月日: 08/11/06 最新の投稿
Yes you need to create serviceprehook. In the hook you need to create a map for the things that you need. And then set back in request. Please find the pseudocode below
//Original map
Map vmVariables = (Map)req.getAttribute(WebKeys.VM_VARIABLES);

//Your map
Map myVariables = new HashMap();
myVariables.set(key,value)

//if(vmVariables is null){
req.setAttribute(WebKeys.VM_VARIABLES,myVariable)
}else{
vmVariables.putAll(myVariables)
req.setAttribute(WebKeys.VM_VARIABLES,vmVariables)
}

Regards,
Sandeep
thumbnail
12年前 に Sagar A Vyas によって更新されました。

RE: Best way to share variable across multiple themes

Liferay Master 投稿: 679 参加年月日: 09/04/17 最新の投稿
Hi Sandeep,

Thanks for sharing this.

Have few questions.

1) Where $themeDisplay,$portletDisplay,$fullTemplatesPath,etc variables are created and injected ?
2) How init.vm file is available at global level? is it imported any where or what ?
3) Once i inject my own variable in it,is it accessible in init.vm ?

Thanks,
Sagar Vyas
thumbnail
12年前 に Sandeep Nair によって更新されました。

RE: Best way to share variable across multiple themes

Liferay Legend 投稿: 1744 参加年月日: 08/11/06 最新の投稿
1) Where $themeDisplay,$portletDisplay,$fullTemplatesPath,etc variables are created and injected ? - VelocityVariables
2) How init.vm file is available at global level? is it imported any where or what ? -- VelocityVariables in 6.0EESp1 and VelocityVariablesImpl in 6.0 EE SP2 velocityContext.put(
"init",
themeDisplay.getPathContext() +
VelocityResourceListener.SERVLET_SEPARATOR +
"/html/themes/_unstyled/templates/init.vm");


3) Once i inject my own variable in it,is it accessible in init.vm ? - Yes
thumbnail
12年前 に Sagar A Vyas によって更新されました。

RE: Best way to share variable across multiple themes

Liferay Master 投稿: 679 参加年月日: 09/04/17 最新の投稿
Thank You Sandeep emoticon

Regards,
Sagar Vyas
12年前 に Jesse Paria によって更新されました。

RE: Best way to share variable across multiple themes

Junior Member 投稿: 69 参加年月日: 11/03/04 最新の投稿
I just realized that I can't modify portlet-ext.properties so I need another method other than custom variables.

Suggestions?


Thanks
Jesse
thumbnail
12年前 に Sandeep Nair によって更新されました。

RE: Best way to share variable across multiple themes

Liferay Legend 投稿: 1744 参加年月日: 08/11/06 最新の投稿
Why do you need portal-ext.properties. If you are just trying to read from the property file and set it in velocity variables to be able to access in theme, then the better option is just put values in portal-ext.properties and use $propsUtil in vm to get the value

Else if you want to read from property and set it in variable(which is double work according to my option), bundle the property in hook itself using property hook and use the same in your custom servicepreaction class

Regards,
Sandeep