Foren

Variables in CMS Templates

thumbnail
Ahmad Heba Tul Baseet, geändert vor 12 Jahren.

Variables in CMS Templates

Junior Member Beiträge: 71 Beitrittsdatum: 12.05.11 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Variables in CMS Templates

Regular Member Beiträge: 139 Beitrittsdatum: 10.09.07 Neueste Beiträge
Hi there,

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

journal.template.velocity.restricted.variables=serviceLocator

HTH,
Sharan
thumbnail
Sandeep Nair, geändert vor 12 Jahren.

RE: Variables in CMS Templates

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Variables in CMS Templates

Junior Member Beiträge: 71 Beitrittsdatum: 12.05.11 Neueste Beiträge
All right, I give it a try and let you now. Are there any side effects of that?
thumbnail
Jan Gregor, geändert vor 12 Jahren.

RE: Variables in CMS Templates

Regular Member Beiträge: 224 Beitrittsdatum: 20.10.10 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Variables in CMS Templates

Junior Member Beiträge: 71 Beitrittsdatum: 12.05.11 Neueste Beiträge
ok Thanks. Great explanation.
thumbnail
Ahmad Heba Tul Baseet, geändert vor 12 Jahren.

RE: Variables in CMS Templates

Junior Member Beiträge: 71 Beitrittsdatum: 12.05.11 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Variables in CMS Templates

Liferay Legend Beiträge: 1744 Beitrittsdatum: 06.11.08 Neueste Beiträge
Can you please try $request.attributes.LAYOUT.get('layoutId')

Regards,
Sandeep
thumbnail
Mayur Patel, geändert vor 12 Jahren.

RE: Variables in CMS Templates

Expert Beiträge: 358 Beitrittsdatum: 17.11.10 Neueste Beiträge
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, geändert vor 12 Jahren.

RE: Variables in CMS Templates

Junior Member Beiträge: 71 Beitrittsdatum: 12.05.11 Neueste Beiträge
Hi, Thanks a lot.

I give it a try.

Cheers.
thumbnail
Ahmad Heba Tul Baseet, geändert vor 12 Jahren.

RE: Variables in CMS Templates

Junior Member Beiträge: 71 Beitrittsdatum: 12.05.11 Neueste Beiträge
Thanks Mayeur,

it worked like a charm.

Ahmad
thumbnail
Mayur Patel, geändert vor 12 Jahren.

RE: Variables in CMS Templates

Expert Beiträge: 358 Beitrittsdatum: 17.11.10 Neueste Beiträge
Glad to know this emoticon so, now you can make use of those objects and play around
thumbnail
Ahmad Heba Tul Baseet, geändert vor 12 Jahren.

RE: Variables in CMS Templates

Junior Member Beiträge: 71 Beitrittsdatum: 12.05.11 Neueste Beiträge
I alreday tried it. also getParams("layoutId"). Its not working. But any way .. thnx