Issue
- The goal is to retrieve, via Liferay's API, when a web content article is associated with a Display Page Template.
Environment
- Liferay DXP 7.4+
Resolution
-
Attached is a Groovy script as an example, through which the display page template associated with a particular web content would be retrieved. It only uses the following API services:
- JournalArticle
- AssetDisplayPageEntry -> this latter is the service that provides access to page templates associated with any type of asset, particularly web contents
-
import com.liferay.journal.service.JournalArticleLocalServiceUtil
import com.liferay.asset.display.page.service.AssetDisplayPageEntryLocalServiceUtil
import com.liferay.journal.model.JournalArticle
import com.liferay.asset.display.page.model.AssetDisplayPageEntry
JournalArticle journal=JournalArticleLocalServiceUtil.fetchArticle(X)
classnameid = com.liferay.portal.kernel.service.ClassNameLocalServiceUtil.getClassNameId(JournalArticle.class)
AssetDisplayPageEntry aseetEntry=AssetDisplayPageEntryLocalServiceUtil.fetchAssetDisplayPageEntry(journal.getGroupId(),classnameid ,journal.getResourcePrimKey())
out.println(aseetEntry.getLayoutPageTemplateEntryId());
-
Particularities:
- In the first part, a normal web content is retrieved by its ID; In this case, we have used 'X'.
- Using the AssetDisplayPageEntryLocalServiceUtil API with the parameters obtained from the previous Journal, it coud be obtained the associated AssetDisplayPageEntry model, which contains a LayoutPageTemplateEntryId field. This field would contain the identifier of the page template associated with the asset or 0 in case it doesn't have one.