構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Jesse Paria
Best way to share variable across multiple themes
2011/12/05 19:52
答え

Jesse Paria

ランク: Junior Member

投稿: 69

参加年月日: 2011/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
Sagar A Vyas
RE: Best way to share variable across multiple themes
2011/12/05 21:19
答え

Sagar A Vyas

ランク: Liferay Master

投稿: 655

参加年月日: 2009/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
Jesse Paria
RE: Best way to share variable across multiple themes
2011/12/05 22:39
答え

Jesse Paria

ランク: Junior Member

投稿: 69

参加年月日: 2011/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
Sagar A Vyas
RE: Best way to share variable across multiple themes
2011/12/05 22:47
答え

Sagar A Vyas

ランク: Liferay Master

投稿: 655

参加年月日: 2009/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
Sandeep Nair
RE: Best way to share variable across multiple themes
2011/12/05 22:49
答え

Sandeep Nair

ランク: Liferay Legend

投稿: 1693

参加年月日: 2008/11/05

最近の投稿

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
Sagar A Vyas
RE: Best way to share variable across multiple themes
2011/12/05 22:57
答え

Sagar A Vyas

ランク: Liferay Master

投稿: 655

参加年月日: 2009/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
Sandeep Nair
RE: Best way to share variable across multiple themes
2011/12/05 23:05
答え

Sandeep Nair

ランク: Liferay Legend

投稿: 1693

参加年月日: 2008/11/05

最近の投稿

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
Sagar A Vyas
RE: Best way to share variable across multiple themes
2011/12/05 23:13
答え

Sagar A Vyas

ランク: Liferay Master

投稿: 655

参加年月日: 2009/04/17

最近の投稿

Thank You Sandeep emoticon

Regards,
Sagar Vyas
Jesse Paria
RE: Best way to share variable across multiple themes
2011/12/05 23:16
答え

Jesse Paria

ランク: Junior Member

投稿: 69

参加年月日: 2011/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
Sandeep Nair
RE: Best way to share variable across multiple themes
2011/12/05 23:27
答え

Sandeep Nair

ランク: Liferay Legend

投稿: 1693

参加年月日: 2008/11/05

最近の投稿

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