Fóruns

Início » Liferay Portal » English » 3. Development

Visualização combinada Visão plana Exibição em árvore
Tópicos [ Anterior | Próximo ]
toggle
Ahmad Heba Tul Baseet
Variables in CMS Templates
22 de Dezembro de 2011 02:39
Resposta

Ahmad Heba Tul Baseet

Ranking: Junior Member

Mensagens: 70

Data de entrada: 12 de Maio de 2011

Mensagens recentes

Hi all,
One question. In CMS Templates, we can access Structure variables thru $strutureVariableName.

Can we get Layout variable or set somehow $layout in CMS Templates.
I tried with
1
2#set($layoutLocalService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))

but I think $servicelocator is not there. So in simple words,
how to access $layout in CMS Templates, so I can get the layout id of the page, in which that CMS Template/Webcontent is been called.
Sharana Basavaraj Ballari
RE: Variables in CMS Templates
22 de Dezembro de 2011 02:53
Resposta

Sharana Basavaraj Ballari

Ranking: Regular Member

Mensagens: 139

Data de entrada: 9 de Setembro de 2007

Mensagens recentes

Hi there,

Have you added the below property in portal-ext.properties file ??

journal.template.velocity.restricted.variables=serviceLocator

HTH,
Sharan
Sandeep Nair
RE: Variables in CMS Templates
22 de Dezembro de 2011 02:56
Resposta

Sandeep Nair

Ranking: Liferay Legend

Mensagens: 1721

Data de entrada: 5 de Novembro de 2008

Mensagens recentes

Please add teh following following property in portal-ext.properties

journal.template.velocity.restricted.variables=

Then you should be able to use servicelocator in CMS template
Ahmad Heba Tul Baseet
RE: Variables in CMS Templates
22 de Dezembro de 2011 02:59
Resposta

Ahmad Heba Tul Baseet

Ranking: Junior Member

Mensagens: 70

Data de entrada: 12 de Maio de 2011

Mensagens recentes

All right, I give it a try and let you now. Are there any side effects of that?
Jan Gregor
RE: Variables in CMS Templates
22 de Dezembro de 2011 03:09
Resposta

Jan Gregor

Ranking: Regular Member

Mensagens: 224

Data de entrada: 20 de Outubro de 2010

Mensagens recentes

Basically the servicelocator is deactivated from security reasons. Using it you have full access to the Service API, so basically you can do whatever you want. Once you want to have this control (i.e to access som Service) one way to do it is this way. Other, more complex way, is to add some custom velocity variables to request, which you can then use in your template.

Regards,
Jan.
Ahmad Heba Tul Baseet
RE: Variables in CMS Templates
22 de Dezembro de 2011 03:31
Resposta

Ahmad Heba Tul Baseet

Ranking: Junior Member

Mensagens: 70

Data de entrada: 12 de Maio de 2011

Mensagens recentes

ok Thanks. Great explanation.
Ahmad Heba Tul Baseet
RE: Variables in CMS Templates
22 de Dezembro de 2011 04:08
Resposta

Ahmad Heba Tul Baseet

Ranking: Junior Member

Mensagens: 70

Data de entrada: 12 de Maio de 2011

Mensagens recentes

Actually I wanted the layout ID, and I checked the
1 $request.attributes.LAYOUT
. It has layoutid.

But
1$request.attributes.LAYOUT.layoutId
or
1$request.attributes.LAYOUT.friendlyURL
ist not giving back anything.


but $request.attributes.LAYOUT gives back

{uuid=8773d302-006f-4874-82ce-5b7496aeb028, plid=59825, groupId=59110, companyId=59085, privateLayout=false, layoutId=16, parentLayoutId=4, name=Doppelmedikation, title=, description=, type=portlet, typeSettings=layout-template-id=2_columns_ii column-2=56_INSTANCE_q2pT column-1=56_INSTANCE_h5EK, , hidden=false, friendlyURL=/doppelmedikation1, iconImage=false, iconImageId=0, themeId=, colorSchemeId=, wapThemeId=, wapColorSchemeId=, css=, priority=1, layoutPrototypeId=0, dlFolderId=0}

How can I access
1$request.attributes.LAYOUT.friendlyURL


I am an CMS Web Content Templates
Thanks
Sandeep Nair
RE: Variables in CMS Templates
22 de Dezembro de 2011 05:27
Resposta

Sandeep Nair

Ranking: Liferay Legend

Mensagens: 1721

Data de entrada: 5 de Novembro de 2008

Mensagens recentes

Can you please try $request.attributes.LAYOUT.get('layoutId')

Regards,
Sandeep
Mayur Patel
RE: Variables in CMS Templates
22 de Dezembro de 2011 06:13
Resposta

Mayur Patel

Ranking: Expert

Mensagens: 349

Data de entrada: 17 de Novembro de 2010

Mensagens recentes

It seems $request.attributes.LAYOUT.layoutId cant accessible,

To access the layout object, you can take the layout id from the following code, and then call the layout service and access the full object.

##take layout id
#set ($layoutId = $request.get("theme-display").get("plid"))

##get the service for layout
#set($layoutService = $serviceLocator.findService("com.liferay.portal.service.LayoutLocalService"))

##convert the layout id into long
#set ($layoutLong = $getterUtil.getLong($layoutId))

##take a layout object
#set($layout = $layoutService.getLayout($layoutLong))

HTH,
Mayur
Ahmad Heba Tul Baseet
RE: Variables in CMS Templates
22 de Dezembro de 2011 07:02
Resposta

Ahmad Heba Tul Baseet

Ranking: Junior Member

Mensagens: 70

Data de entrada: 12 de Maio de 2011

Mensagens recentes

Hi, Thanks a lot.

I give it a try.

Cheers.
Ahmad Heba Tul Baseet
RE: Variables in CMS Templates
22 de Dezembro de 2011 07:03
Resposta

Ahmad Heba Tul Baseet

Ranking: Junior Member

Mensagens: 70

Data de entrada: 12 de Maio de 2011

Mensagens recentes

I alreday tried it. also getParams("layoutId"). Its not working. But any way .. thnx
Ahmad Heba Tul Baseet
RE: Variables in CMS Templates
22 de Dezembro de 2011 07:16
Resposta

Ahmad Heba Tul Baseet

Ranking: Junior Member

Mensagens: 70

Data de entrada: 12 de Maio de 2011

Mensagens recentes

Thanks Mayeur,

it worked like a charm.

Ahmad
Mayur Patel
RE: Variables in CMS Templates
22 de Dezembro de 2011 07:22
Resposta

Mayur Patel

Ranking: Expert

Mensagens: 349

Data de entrada: 17 de Novembro de 2010

Mensagens recentes

Glad to know this emoticon so, now you can make use of those objects and play around