How to display journal content inside a portlet
Sometimes you want a portlet contains some texts from journal article, so user can easily edit the text. In that case you have to modify the presentation file of your portlet ( whether it’s a JSP file, VM, etc ), to display the content. You can use com.liferay.portlet.journalcontent.util.JournalContentUtil class to display the content. Assume that you use JSP for your presentation and you use ext environment for your portlet, here are the steps to do it :
- Include /html/portlet/init.jsp on your portlet’s JSP.
- Include com.liferay.portlet.journalcontent.util.JournalContentUtil in your JSP file
- Get your journal article’s id
- Call getContent method of JournalContentUtil inside the JSP
Let’s go to the details.
Include /html/portlet/init.jsp on your portlet’s JSP like this :
<%@ include file="/html/portlet/init.jsp" %>Include JournalContentUtil on your JSP file, like this
<%@ page import="com.liferay.portlet.journalcontent.util.JournalContentUtil" %>Create your journal article, after you save your article, Liferay will generate an id for your article. Take note of this id, so we can use on our method call as argument later in our JSP page.
Now on your portlet’s JSP, create a code like this
<div id="journal-article-import" > <% String articleId = "13734"; // this is Journal Article's Id String languageId = LanguageUtil.getLanguageId( renderRequest ); String content = JournalContentUtil.getContent( themeDisplay.getPortletGroupId(), articleId, languageId, themeDisplay); %> <%= content %> </div>themeDisplay is implicit variable inside page context, that is set using Liferay's custom tag ;.
The definition of this custom tag can be seen on liferay-theme.tld. Here is the related content of liferay-theme.tld
<tag> <name>defineObjects</name> <tag-class>com.liferay.taglib.theme.DefineObjectsTag</tag-class> <tei-class>com.liferay.taglib.theme.DefineObjectsTei</tei-class> <body-content>empty</body-content> </tag>So if you want to find out what are other implicit variables that was set whenever you include /html/portlet/init.jsp, you can take a look at com.liferay.taglib.theme.DefineObjectsTag class.
Done. Tested on Liferay 5.1.1
hi! is there any way to do the same in a portlet create in SDK enviroment instead EXT enviroment?
Thanks in advance