For last couple of days I have been working on this new feature introduced in Liferay 6.2 Application Display Templates (aka ADT).
ADT Provides adding custom display settings to our portlets. Initially when liferay 6.2 was released ADT can only be applied to a specified list of OOTB portlets
ADT Provides adding custom display settings to our portlets. Initially when liferay 6.2 was released ADT can only be applied to a specified list of OOTB portlets
- Asset Publisher
- Blogs
- Categories Navigation
- Media Gallery
- Site Map
- Tags Navigation
- Wiki
But later the scope is extended to have ADT's for custom portlets as well.
That being said let me focus of the heading of this blog.
Document Type holds the meta data of the document and can be created in the liferay portal with different scopes (Global, Portal, Site). Document Type can be defined to have different fields with different data types. We can also restrict a folder to have a specified document type.
There is no direct API for retrieving the document type field values for a given document, for a given document. Thus it becomes more complicated to retrieve those in the free marker template.
- By default serviceLocator variable is restricted in portal.properties we need to enable serviceLocator in portal-ext.properties, by adding below line, so that we can access different liferay servcies.
- freemarker.engine.restricted.variables=
- Retrieve DLFileEntryLocalService with service Locator
- <#assign dlFileEntryService = serviceLocator.findService("com.liferay.portlet.documentlibrary.service.DLFileEntryLocalService")>
- Retrieve the DLFileEntry Object for a given FileEntry Object
- <#assign dlFileEntry = dlFileEntryService.getFileEntry(curFileEntry.getFileEntryId() )>
- From the DLFileEntry get all the fields available as Map.
- <#assign fieldsMap = dlFileEntry.getFieldsMap(dlFileEntry.getFileVersion().getFileVersionId()) >
- Now Iterate through the Map and retrieve the fields available in the document type of a given document.
<#list fieldsMap?keys as structureKey>
<#list fieldsMap[structureKey].iterator() as field>
</#list><#assign imgList = imgList + {field.getValue():curFileEntry}>
</#list>
That is all we need to do.
Here are some useful links that might be helpful while developing the ADT's
http://www.liferay.com/web/james.falkner/blog/-/blogs/dumping-adt-wcm-template-variables?_33_redirect=http%3A%2F%2Fwww.liferay.com%2Fweb%2Fjames.falkner%2Fblog%3Fp_p_id%3D33%26p_p_lifecycle%3D0%26p_p_state%3Dnormal%26p_p_mode%3Dview%26p_p_col_id%3Dcolumn-2%26p_p_col_count%3D1
https://www.liferay.com/community/forums/-/message_boards/message/44019133
https://www.liferay.com/es/community/forums/-/message_boards/message/44197544
https://issues.liferay.com/browse/LPS-50931
http://www.liferay.com/web/eduardo.garcia/blog/-/blogs/new-ways-of-customization-with-application-display-templates-part-i-
http://www.liferay.com/web/eduardo.garcia/blog/-/blogs/new-ways-of-customization-with-application-display-templates-part-ii-