Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Ahmad Heba Tul Baseet
Variables in CMS Templates
December 22, 2011 2:39 AM
Answer

Ahmad Heba Tul Baseet

Rank: Junior Member

Posts: 70

Join Date: May 12, 2011

Recent Posts

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
December 22, 2011 2:53 AM
Answer

Sharana Basavaraj Ballari

Rank: Regular Member

Posts: 139

Join Date: September 9, 2007

Recent Posts

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
December 22, 2011 2:56 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1731

Join Date: November 5, 2008

Recent Posts

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
December 22, 2011 2:59 AM
Answer

Ahmad Heba Tul Baseet

Rank: Junior Member

Posts: 70

Join Date: May 12, 2011

Recent Posts

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
December 22, 2011 3:09 AM
Answer

Jan Gregor

Rank: Regular Member

Posts: 224

Join Date: October 20, 2010

Recent Posts

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
December 22, 2011 3:31 AM
Answer

Ahmad Heba Tul Baseet

Rank: Junior Member

Posts: 70

Join Date: May 12, 2011

Recent Posts

ok Thanks. Great explanation.
Ahmad Heba Tul Baseet
RE: Variables in CMS Templates
December 22, 2011 4:08 AM
Answer

Ahmad Heba Tul Baseet

Rank: Junior Member

Posts: 70

Join Date: May 12, 2011

Recent Posts

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
December 22, 2011 5:27 AM
Answer

Sandeep Nair

Rank: Liferay Legend

Posts: 1731

Join Date: November 5, 2008

Recent Posts

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

Regards,
Sandeep
Mayur Patel
RE: Variables in CMS Templates
December 22, 2011 6:13 AM
Answer

Mayur Patel

Rank: Expert

Posts: 350

Join Date: November 17, 2010

Recent Posts

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
December 22, 2011 7:02 AM
Answer

Ahmad Heba Tul Baseet

Rank: Junior Member

Posts: 70

Join Date: May 12, 2011

Recent Posts

Hi, Thanks a lot.

I give it a try.

Cheers.
Ahmad Heba Tul Baseet
RE: Variables in CMS Templates
December 22, 2011 7:03 AM
Answer

Ahmad Heba Tul Baseet

Rank: Junior Member

Posts: 70

Join Date: May 12, 2011

Recent Posts

I alreday tried it. also getParams("layoutId"). Its not working. But any way .. thnx
Ahmad Heba Tul Baseet
RE: Variables in CMS Templates
December 22, 2011 7:16 AM
Answer

Ahmad Heba Tul Baseet

Rank: Junior Member

Posts: 70

Join Date: May 12, 2011

Recent Posts

Thanks Mayeur,

it worked like a charm.

Ahmad
Mayur Patel
RE: Variables in CMS Templates
December 22, 2011 7:22 AM
Answer

Mayur Patel

Rank: Expert

Posts: 350

Join Date: November 17, 2010

Recent Posts

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