RE: Liferay 7 - Add Web Content in Theme

Matteo Gnocchi, modified 9 Years ago. Junior Member Posts: 29 Join Date: 3/29/16 Recent Posts
Hi!
I'd like to add a web content in my theme (FreeMarker) for Liferay 7.
I tried to use the "journalContentUtil.getContent" method but it didn't work.
Probably the journalContentUtil does not exist in liferay 7 anymore (see more)
How can I embed a webcontent in my freemarker theme for Liferay 7?
Thanks!!
thumbnail
Travis Cory, modified 9 Years ago. Junior Member Posts: 73 Join Date: 6/4/13 Recent Posts
Hey Matteo,

Sorry for the frustration. I'd try to see if you can use the Impl class and this method. If calling
${journalContentImpl}
doesn't work try calling
${journalContent}
If you have article Id you can pass in the other variables really easily with variables from init.ftl
Matteo Gnocchi, modified 9 Years ago. Junior Member Posts: 29 Join Date: 3/29/16 Recent Posts
Thanks Travis
Probably I'm doing something wrong but when I try to use "${journalContent}" I get this error: "The following has evaluated to null or missing"
Have you been able to use it?
Matteo
Michele Stoduto, modified 9 Years ago. Junior Member Posts: 42 Join Date: 7/7/10 Recent Posts
Hi Matteo
I've a similar problem for embedded web content in theme.
Have you find any solution?
Can you write the solution?

Tnx
Michele Stoduto, modified 9 Years ago. Junior Member Posts: 42 Join Date: 7/7/10 Recent Posts
i've a possible solution, use runtime portlet into theme:


<#assign VOID = freeMarkerPortletPreferences.setValue("portletSetupPortletDecoratorId", "barebone")>
<@liferay_portlet["runtime"]
defaultPreferences="${freeMarkerPortletPreferences}"
portletProviderAction=portletProviderAction.VIEW
portletName="com_liferay_journal_content_web_portlet_JournalContentPortlet" />
${freeMarkerPortletPreferences.reset()}


the code is valid for a single portlet (Web Content) into theme.
If you want a multi portlet (Web Content) add instanceIdinto tag.

<#assign VOID = freeMarkerPortletPreferences.setValue("portletSetupPortletDecoratorId", "barebone")>
<@liferay_portlet["runtime"]
 defaultPreferences="${freeMarkerPortletPreferences}"
 portletProviderAction=portletProviderAction.VIEW
 instanceId="blablabla1"
 portletName="com_liferay_journal_content_web_portlet_JournalContentPortlet" />
 ${freeMarkerPortletPreferences.reset()}
teodor popescu, modified 9 Years ago. New Member Posts: 4 Join Date: 3/23/16 Recent Posts
What about embedding into Velocity themes?
Has anyone managed to find a solution?

Thanks!
Matteo Gnocchi, modified 9 Years ago. Junior Member Posts: 29 Join Date: 3/29/16 Recent Posts
It works perfectly!
Thank you very Much!!!!
Manushi Jani, modified 8 Years ago. New Member Posts: 9 Join Date: 2/13/15 Recent Posts
<#assign VOID = freeMarkerPortletPreferences.setValue("portletSetupPortletDecoratorId", "barebone") />
<#assign theme_groupID = htmlUtil.escape(theme_display.getCompanyGroupId()?string) />
<#assign VOID = freeMarkerPortletPreferences.setValue("groupId", "yourscopegroupid") />
<#assign VOID = freeMarkerPortletPreferences.setValue("articleId", "yourarticleid") />

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

</div>

Using this code exactly,you can embed the desired journal article(by passing the articleid) in web content display.Please don't forget to include the line instanceId="anynameyoucangive",otherwise it won't reflect.I wasted much time and found this.Hence it is very helpful.
Erik Cochran, modified 8 Years ago. New Member Posts: 8 Join Date: 1/5/17 Recent Posts
Hi Manushi,
How did you figure this out? Also, shouldn't the articleId and instanceId match? I found that another developer placed the instanceId in articleId but captilized the variable. Any reference documentation is much appreciated.
E.
thumbnail
Aritz Galdos, modified 6 Years ago. Expert Posts: 416 Join Date: 5/15/07 Recent Posts

Hi,

 

Here a link to some documentation.

 

https://dev.liferay.com/es/develop/tutorials/-/knowledge_base/7-1/embedding-portlets-in-themes-and-layout-templates

Rashesh Ved, modified 6 Years ago. New Member Posts: 2 Join Date: 11/20/18 Recent Posts

Hii your reply help me alot.


But can you please tell me in this article Id portion if i want to get article Id dynamically then how can I do it?

In my freemarker theme template I tried to access JournalArticleLocalServiceUtil  in following manner it is showing me error mentioning null or missing serviceLocator

<#assign journalArticleLocalServiceUtil = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalServiceUtil")>

I tried to remove all restricted variables as well from front side and restarted server still it's showing same error.

Lee Jordan, modified 6 Years ago. Expert Posts: 449 Join Date: 5/26/15 Recent Posts
This was a frustrating read ... the OP isn't wanting to embed a portlet but a web content article. I would like to do this to add a global footer links section in 7.0 but the trouble would be that the article ID's would be different on DEV QA and Production servers. I looked at adding the article ID in the look-and-feel.xml as a theme custom field, that didn't seem to work.
thumbnail
Fernando Fernandez, modified 5 Years ago. Expert Posts: 401 Join Date: 8/22/07 Recent Posts
Since this is the first result in a google search for this subject I think it's useful too add that since some time ago you can use the JSP taglibs in freemarker
This means that, to display an article  in the footer  you can include something like this in your theme's portal_normal.ftl:

&lt;@liferay_journal["journal-article"]
&nbsp;   articleId=footer_article_id
&nbsp;   groupId=page_group.groupId
/&gt;

Additionally, if you want to use a theme setting config you must:
 
1. Add the setting to the liferay-look-and-feel.xml file from your theme

<settings>
&nbsp; &nbsp; <setting configurable="true" key="footer-article-id" type="text"  />
</settings>

2. Convert the setting into a variable in init_custom.ftl
&lt;#assign&nbsp;footer_article_id&nbsp;=&nbsp;getterUtil.getString(themeDisplay.getThemeSetting("footer-article-id"))/&gt;

HTH

Fernando
Lee Jordan, modified 5 Years ago. Expert Posts: 449 Join Date: 5/26/15 Recent Posts
That would work for sure, but I have 500 sites. Nobody on my team is going to go through 500 sites setting a theme setting, multiply that by 3 because we have three environments. Nope.  The issue as stated with the article ID, it's going to be different between three environments, so you can't deploy the theme to different environments with an article ID hard-coded.

Also ... defaultPreferences="${freeMarkerPortletPreferences}" doesn't seem to work and there's zero helpful documentation, beyond setting the decorator to borderless. Which ok is helpful but that one example doesn't then tell anyone how to access actual portlet configurations, there's no codex or index of these possibilities, in fact there is zero documentation on the inbuilt portlets for developers period. Liferay documentation is written with a lot of assumptions by people who are close to Liferay. Nobody else has a chance with the documentation. Litterally the documentation is ok you can set barebones, you're a pro!!!

The only suggestion seems to be to get the portlet preferences by looking at the database? A front end developer is not going to be looking at a database table, sorry they just won't.

I am using theme settings though to allow users to hide show UI elements though.