Accessing Article Information in Web Content Templates

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_TAG_NAMES = "reserved-article-asset-tag-names";
  public static final String RESERVED_ARTICLE_AUTHOR_COMMENTS = "reserved-article-author-comments";
  public static final String RESERVED_ARTICLE_AUTHOR_EMAIL_ADDRESS = "reserved-article-author-email-address";
  public static final String RESERVED_ARTICLE_AUTHOR_ID = "reserved-article-author-id";
  public static final String RESERVED_ARTICLE_AUTHOR_JOB_TITLE = "reserved-article-author-job-title";
  public static final String RESERVED_ARTICLE_AUTHOR_LOCATION =  "reserved-article-author-location";
  public static final String RESERVED_ARTICLE_AUTHOR_NAME = "reserved-article-author-name";
  public static final String RESERVED_ARTICLE_AUTHOR_ORGANIZATION =  "reserved-article-author-organization";
  public static final String RESERVED_ARTICLE_CREATE_DATE = "reserved-article-create-date";
  public static final String RESERVED_ARTICLE_DESCRIPTION = "reserved-article-description";
  public static final String RESERVED_ARTICLE_DISPLAY_DATE = "reserved-article-display-date";
  public static final String RESERVED_ARTICLE_ID = "reserved-article-id";
  public static final String RESERVED_ARTICLE_MODIFIED_DATE = "reserved-article-modified-date";
  public static final String RESERVED_ARTICLE_SMALL_IMAGE_URL =  "reserved-article-small-image-url";
  public static final String RESERVED_ARTICLE_TITLE = "reserved-article-title";
  public static final String RESERVED_ARTICLE_TYPE = "reserved-article-type";
  public static final String RESERVED_ARTICLE_URL_TITLE = "reserved-article-url-title";
  public static final String RESERVED_ARTICLE_VERSION ="reserved-article-version";
}

Comments

Popular posts from this blog

Liferay Search Container Example

Liferay DXP - max upload file size

Liferay Keycloak integration