0

I know how to get groupid in liferay velocity theme using:

#set ($scopeGroupId = $getterUtil.getLong($group_id))

However I also need to get a folder's ID using its name.
I have been researching for a while and don't seem to find a way to do that.

Q: Is this enabled and feasible in liferay 6.2?

chadct
  • 43
  • 1
  • 9

1 Answers1

2

Make sure that you are allowed to use serviceLocator or add in your portal-ext.properties this entry:

velocity.engine.restricted.variables=

After that you can use this code in your template:

#set ($folderLocalService =$serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFolderLocalService"))
#set ($folderId = $folderLocalService.getFolder($groupId,0,"folder_name").getFolderId())

$folderId 

Or you can use another method from DLFolderLocalService.

glw
  • 1,646
  • 1
  • 16
  • 20
  • it is not working, it displays in browser $folderId . What might be the issue? – chadct Jan 27 '16 at 04:30
  • Did you add this property `velocity.engine.restricted.variables=`? Or maybe folder doesn't exist. Look at parameters in `getFolder`, second one is `parentFolderId` in above example. – glw Jan 27 '16 at 09:53
  • yes I added the property, and the folder name I am using exists. It doesn't have a parentfolder, which means parentfolderid should be 0 correct? – chadct Jan 27 '16 at 15:46
  • Yes, 0 is default id for root folder. Which version of Liferay are you using? I've checked on `liferay-portal-6.2-ce-ga5`. – glw Jan 28 '16 at 20:59