Posts

Showing posts with the label webcontent

Liferay 7: Display Page for Journal Article

Image
 Setup a Display Page for a Web Content (Journal Article) in Liferay 7 Manual and Programmatic Approach Overview You may need to define the JournalArticle display page to configure the layout, where the article should be displayed (for example, when clicking on the “Read More” link in Asset Publisher). Of course, you may do this manually in article configuration. But, if you create articles programmatically, you’ll need to set up the display page programmatically also. This article will cover both approaches. Manual setup To set up the DisplayPage manually - go to the Edit Article page (Site Menu -> Content & Data -> Web Content, and click on the article you need).  On the sidebar to the right find the “Display Page Template” section, choose “Specific Display Page Template”, and click the “Select” button. In the popup, find the page you need (either on Public Pages or Private Pages tab): Note: only those pages are available for selection,...

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...