9

I have found how to embed WebContent in Liferay 6.2 theme using journalContentUtil.getContent method. My question is how to do the same thing in Liferay 7?

ahajib
  • 12,838
  • 29
  • 79
  • 120
Stefania Izzo
  • 180
  • 1
  • 11

4 Answers4

6

I have found the way fix web content via custom ftl template in Liferay 7/DXP.

Below is the sample code,

<#assign VOID = freeMarkerPortletPreferences.setValue("portletSetupPortletDecoratorId", "barebone") />
<#assign theme_groupID = htmlUtil.escape(theme_display.getCompanyGroupId()?string) />
<#assign VOID = freeMarkerPortletPreferences.setValue("groupId", '${group_id}') />
<#assign VOID = freeMarkerPortletPreferences.setValue("articleId", "yourarticleid") />



        <@liferay_portlet["runtime"]
        defaultPreferences="${freeMarkerPortletPreferences}"
        portletProviderAction=portletProviderAction.VIEW
        instanceId="footercontent"
        portletName="com_liferay_journal_content_web_portlet_JournalContentPortlet" />
        ${freeMarkerPortletPreferences.reset()}

Make sure the articleId which you are providing in preferences is under the groupId.Means group/site should contains the webcontent.

Abhishek Suthar
  • 674
  • 1
  • 8
  • 27
  • This is great, work for me! My question is, how did you figure out how to do this? I could no find any documentation on how to use the @liferay_portlet["runtime"] – gus3001 Nov 01 '16 at 09:38
  • 1
    The documentation could be found here: [EMBEDDING PORTLETS IN THEMES AND LAYOUT TEMPLATES](https://dev.liferay.com/develop/tutorials/-/knowledge_base/7-0/embedding-portlets-in-themes-and-layout-templates) – Matthias Heinrich May 28 '18 at 12:42
3

For embedding WebContent in Liferay 7, first of all, you have to enable serviceLocator in Control Panel -> Configuration -> System Settings -> Foundation -> FreeMarker Engine -> Restricted Variables. There you can remove serviceLocator

Now you can use it for example in Application Display Template (Freemarker):

<#assign liferay_ui = taglibLiferayHash["/META-INF/liferay-ui.tld"] />

<#assign journalArticleLocalService = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService") />

and then use the journalArticleLocalService to retrieve the WebContent doing

getArticleContent(long groupId, String articleId, double version, String viewMode, String ddmTemplateKey, String languageId, ThemeDisplay themeDisplay)
Stefania Izzo
  • 180
  • 1
  • 11
  • Technically, I think this answer is more accurate however I like the answer from @abhishek-suthar since the content will be added with the portlet controls and it is easer for the admin to edit. If you just want to add the html, this method works best. Just to complement the last line of code, this is an example of how to call the method ```<#assign article = journalArticleLocalService.fetchArticle(group_id, "FOOTER")>``` then ```${journalArticleLocalService.getArticleContent(article, article.getDDMTemplateKey(), "VIEW", locale, themeDisplay)}``` – gus3001 Nov 01 '16 at 09:42
  • Thank you this works! However in 7.1 we lose access to certain context variables like `requestMap`. – protoEvangelion Feb 05 '19 at 00:37
1

The closest class to journalContentUtil is JournalContentImpl and it does have almost the same methods related to getContent. You can see the code here JournalContentImpl

KlajdPaja
  • 959
  • 1
  • 8
  • 17
0

You can use the JSP taglibs in freemarker.

This means that, to display an article you can include something like this:

<@liferay_journal["journal-article"]
articleId=footer_article_id
groupId=page_group.groupId
/>