Posts

Showing posts with the label ddm

Registering custom objects for WebContent Templates with TemplateContextContributor

Registering custom objects for WebContent Templates with TemplateContextContributor Sometimes you may need additional data to be available in the web content template. TemplateContextContributor  can help in this case: Create class, that implements  com.liferay.portal.kernel.template.TemplateContextContributor . Add  @Component  annotation to rigister it as OSGi-component. Override  com.lif.app.display.contributor.AppDisplayContributor.prepare(Map<String, Object> contextObjects, HttpServletRequest request)  method and put required object into  contextObjects  map. Deploy module with template context contributor. Use registered context in FTL template for web content. Example: @Component ( immediate = true , property = "type=" + TemplateContextContributor. TYPE_GLOBAL , service = TemplateContextContributor. class ) public class AppDisplayContributor implements TemplateContextContributor { private ...

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.