Fórum

Variables in CMS Templates

thumbnail
Ahmad Heba Tul Baseet, modificado 12 Anos atrás.

Variables in CMS Templates

Junior Member Postagens: 71 Data de Entrada: 12/05/11 Postagens 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

#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.
thumbnail
Sharana Basavaraj Ballari, modificado 12 Anos atrás.

RE: Variables in CMS Templates

Regular Member Postagens: 139 Data de Entrada: 10/09/07 Postagens Recentes
Hi there,

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

journal.template.velocity.restricted.variables=serviceLocator

HTH,
Sharan
thumbnail
Sandeep Nair, modificado 12 Anos atrás.

RE: Variables in CMS Templates

Liferay Legend Postagens: 1744 Data de Entrada: 06/11/08 Postagens 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
thumbnail
Ahmad Heba Tul Baseet, modificado 12 Anos atrás.

RE: Variables in CMS Templates

Junior Member Postagens: 71 Data de Entrada: 12/05/11 Postagens Recentes
All right, I give it a try and let you now. Are there any side effects of that?
thumbnail
Jan Gregor, modificado 12 Anos atrás.

RE: Variables in CMS Templates

Regular Member Postagens: 224 Data de Entrada: 20/10/10 Postagens 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.
thumbnail
Ahmad Heba Tul Baseet, modificado 12 Anos atrás.

RE: Variables in CMS Templates

Junior Member Postagens: 71 Data de Entrada: 12/05/11 Postagens Recentes
ok Thanks. Great explanation.
thumbnail
Ahmad Heba Tul Baseet, modificado 12 Anos atrás.

RE: Variables in CMS Templates

Junior Member Postagens: 71 Data de Entrada: 12/05/11 Postagens Recentes
Actually I wanted the layout ID, and I checked the
 $request.attributes.LAYOUT
. It has layoutid.

But
$request.attributes.LAYOUT.layoutId
or
$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
$request.attributes.LAYOUT.friendlyURL


I am an CMS Web Content Templates
Thanks
thumbnail
Sandeep Nair, modificado 12 Anos atrás.

RE: Variables in CMS Templates

Liferay Legend Postagens: 1744 Data de Entrada: 06/11/08 Postagens Recentes
Can you please try $request.attributes.LAYOUT.get('layoutId')

Regards,
Sandeep
thumbnail
Mayur Patel, modificado 12 Anos atrás.

RE: Variables in CMS Templates

Expert Postagens: 358 Data de Entrada: 17/11/10 Postagens 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
thumbnail
Ahmad Heba Tul Baseet, modificado 12 Anos atrás.

RE: Variables in CMS Templates

Junior Member Postagens: 71 Data de Entrada: 12/05/11 Postagens Recentes
Hi, Thanks a lot.

I give it a try.

Cheers.
thumbnail
Ahmad Heba Tul Baseet, modificado 12 Anos atrás.

RE: Variables in CMS Templates

Junior Member Postagens: 71 Data de Entrada: 12/05/11 Postagens Recentes
Thanks Mayeur,

it worked like a charm.

Ahmad
thumbnail
Mayur Patel, modificado 12 Anos atrás.

RE: Variables in CMS Templates

Expert Postagens: 358 Data de Entrada: 17/11/10 Postagens Recentes
Glad to know this emoticon so, now you can make use of those objects and play around
thumbnail
Ahmad Heba Tul Baseet, modificado 12 Anos atrás.

RE: Variables in CMS Templates

Junior Member Postagens: 71 Data de Entrada: 12/05/11 Postagens Recentes
I alreday tried it. also getParams("layoutId"). Its not working. But any way .. thnx