Unfortunately, this information is not directly accessible from the $f
variable that was injected in your template by Liferay. For Liferay 6.1, the $f.data
holds the url to the document in the following form:
/documents/[group-id]/[folder-id]/[file-name]
Luckily, we can hack our way through this and get hold of the actual file by using the service API, which is accessible in Velocity templates thanks to the $serviceLocator
. For this variable to be available, you must enable it in portal-ext.properties
by configuring the following property:
#
# Input a comma delimited list of variables which are restricted from the
# context in Velocity based Journal templates.
#
journal.template.velocity.restricted.variables=
Once we have this enabled, we can call the right service to retrieve a FileEntry
object based on the parts in the document URL. And then we have the size as well:
#set($url = $f.data)
#set($parts = $stringUtil.split($url, "/"))
#set($group_id = $getterUtil.getLong($parts.get(2)))
#set($folder_id = $getterUtil.getLong($parts.get(3)))
#set($doc_name = $parts.get(4))
#set($docService = $serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLAppLocalService"))
#set($fileEntry = $docService.getFileEntry($group_id, $folder_id, $doc_name))
The file size is: $fileEntry.size