This blog helps you to fetch the “Journal Article Content “or “web content “in different ways based upon our requirement.
(i) Getting the Journal Article of Particular Name :-
String articleName = “sourabh”;// I need the sourabh web content details
AssetTagassetTag = AssetTagLocalServiceUtil.getTag(themeDisplay.getScopeGroupId(), “mytagname”);
for(AssetEntryassetEntry : assetEntrylist) {
String content = StringPool.BLANK;
content = articleDisplay.getContent();
#set($assetTag =$serviceLocator.findService(‘com.liferay.portlet.asset.service.AssetTagLocalService’))
#set($assetTagObj=$assetTag.getTag($groupId,”myTag”))
(i) Getting the Journal Article of Particular Name :-
String articleName = “sourabh”;// I need the sourabh web content details
String content = StringPool.BLANK;
JournalArticlejournalArticle = JournalArticleLocalServiceUtil.getArticleByUrlTitle (themeDisplay.getScopeGroupId(), articleName);// getting the journalArticle Object based on name
String articleId = journalArticle.getArticleId();
JournalArticleDisplayarticleDisplay = JournalContentUtil.getDisplay (themeDisplay.getScopeGroupId(), articleId,””,themeDisplay.getLanguageId(),themeDisplay);
content = articleDisplay.getContent();// by using display content object I am fetching the data of my sourabh Web content.
(ii) Getting the Journal Article based on Tag Name :-
If we want to fetch the specific tag based web content details then the following code will be useful.
String content = StringPool.BLANK;
AssetTagassetTag = AssetTagLocalServiceUtil.getTag(themeDisplay.getScopeGroupId(), “mytagname”);
long assetTagId = assetTag.getTagId();
List assetEntrylist = AssetEntryLocalServiceUtil.getAssetTagAssetEntries(assetTagId);
for(AssetEntryassetEntry : assetEntrylist) {
JournalArticleResourcejournalArticleResourceObj = JournalArticleResourceLocalServiceUtil.getJournalArticleResource(assetEntry.getClassPK());
JournalArticlejournalArticleObj = JournalArticleLocalServiceUtil.getArticle(themeDisplay.getScopeGroupId(),journalArticleResourceObj.getArticleId());
String articleId = journalArticleObj.getArticleId();
JournalArticleDisplayarticleDisplay = JournalContentUtil.getDisplay (themeDisplay.getScopeGroupId(), articleId,””,themeDisplay.getLanguageId(),themeDisplay);
content = articleDisplay.getContent();
}
(iii) Getting the Journal Article based on Structure Id or Template Id:-
If we want to fetch the specific Structure of template based web content details then the following code will be useful.
String content = StringPool.BLANK;
List articleList = JournalArticleLocalServiceUtil.getStructureArticles(themeDisplay.getScopeGroupId(), “tagId”);
// for template use API getTemplateArticles
for(JournalArticlejournalArticle : articleList) {
String articleId = journalArticle.getArticleId();
JournalArticleDisplayarticleDisplay = JournalContentUtil.getDisplay (themeDisplay.getScopeGroupId(), articleId,””,themeDisplay.getLanguageId(),themeDisplay);
content = articleDisplay.getContent();
}
(iv) Fetching the Journal Article content in template file in Liferay
If we want to fetch the journal article of web content details in template file then the following code will be useful.
The following code will shows the tag based journal Article content in template.
No comments:
Post a Comment