Posts

Showing posts from September, 2019

Accessing Article Information in Web Content Templates

Image
While, it’s pretty simple to access journal article structure fields in template: (you have all these fields listed, and even code sample is generated when you click on it), accessing article information (articleId, author, etc.) is not such straightforward. Solution: To access such information you may use the following syntax: <#assign journalArticleId = . vars [ 'reserved-article-id' ]. data /> This will get the articleId of the article being displayed by the template. In a similar way you can access other fields, sample: <#assign createDate = . vars [ 'reserved-article-create-date' ]. data /> <#assign author = . vars [ 'reserved-article-author-name' ]. data /> All these fields are listed in com.liferay.journal.model.JournalStructureConstants class: public class JournalStructureConstants {    public static final String RESERVED = "reserved" ;    public static final String RESERVED_ARTICLE_ASSET

Disable auto-generate for DDM Structure and Template keys

Image
As highlighted here - it’s hard to fetch auto-generated values of DDM structure and template keys in custom code. Fortunately, it’s easy to disable this auto-generation. 1. Go to Control Panel -> Configuration -> System Settings. 2. Find Dynamic Data Mapping, and click Edit: 3. Uncheck Autogenerate checkboxes: Save configuration, and that’s it. From now structure/template keys can be specified during creation, and, thus, easily referenced in custom code.

ADT Template - fetch DDMTemplate by name

Problem : sometimes you may need to access DDMTemplate in the asset publisher template, you know it’s name and you need to fetch it by name, but, unfortunately, there is no such service for that - you can fetch it only by templateKey: public DDMTemplate getTemplate( long groupId, long classNameId, String templateKey)  As templateKey is generated automatically - it’s not a good idea to hard-code it directly in ADT. Solution : here is an FTL function, which finds the required DDMTemplate in Global scope using the template name: <#function getDDMTemplateByName templateName >    <#assign ddmTemplateLocalService = serviceLocator . findService ( "com.liferay.dynamic.data.mapping.service.DDMTemplateLocalService" ) />    <#assign companyLocalService = serviceLocator . findService ( "com.liferay.portal.kernel.service.CompanyLocalService" ) />    <#assign portalUtil = staticUtil [ "com.liferay.portal.kernel.util.PortalUtil"

Liferay MVC portlet - first steps

Liferay MVC portlet - first steps When you generate an MVC Portlet in Liferay Workspace - you’ll get the following code (sample): Portlet class: @Component (   immediate = true ,   property = {       "com.liferay.portlet.display-category=category.sample" ,       "com.liferay.portlet.instanceable=true" ,       "javax.portlet.init-param.template-path=/" ,       "javax.portlet.init-param.view-template=/view.jsp" ,       "javax.portlet.name=" + UserSearchPortletKeys. UserSearch ,       "javax.portlet.resource-bundle=content.Language" ,       "javax.portlet.security-role-ref=power-user,user"    },   service = Portlet. class ) public class UserSearchPortlet extends MVCPortlet { } Portlet keys class: public class UserSearchPortletKeys {    public static final String UserSearch = "usersearch" ; } Here is a list of first steps to modify here. 1) Change generat