Foros de discusión

Embed web content into theme (freemarker - ftl)

Traolly Xiong, modificado hace 9 años.

Embed web content into theme (freemarker - ftl)

Regular Member Mensajes: 195 Fecha de incorporación: 30/12/11 Mensajes recientes
Hello Community,
Has anyone had any luck with embedding a web content into a ftl theme in Liferay 6.2?
Any help is fully appreciated.

Thanks.
thumbnail
Tanweer Ahmed ., modificado hace 1 año.

RE: Embed web content into theme (freemarker - ftl)

Expert Mensajes: 322 Fecha de incorporación: 11/03/10 Mensajes recientes
Traolly Xiong:
Hello Community,
Has anyone had any luck with embedding a web content into a ftl theme in Liferay 6.2?
Any help is fully appreciated.

Thanks.


Hi Traolly,

Not very sure why ${theme.runtime("56_INSTANCE_instanceId")} does not work.This could be a bug.

However, there is another way of getting the article included in the themes.Use the below script.
${theme.journalArticle("your-article-Id", scopeGroupId ,"template-id-if-available-else-pass-null")}


Hope this helps.

Regards,
Tanweer.
Traolly Xiong, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

Regular Member Mensajes: 195 Fecha de incorporación: 30/12/11 Mensajes recientes
Thanks! Let me give this a try to see if I can embed an web content in a Liferay 6.2 ftl theme. I will let you know how it goes.
Traolly Xiong, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

Regular Member Mensajes: 195 Fecha de incorporación: 30/12/11 Mensajes recientes
Hello Tanweer,
What I found in Liferay 6.2 is that the snippet below does work. What do you recommend the "instanceId" to be in this case?

${theme.runtime("56_INSTANCE_instanceId")}

As for the other snippet, it does not work.

${theme.journalArticle("11832", 10580 ,"14260")}

Did you test this in a 6.2 ftl theme?

Thanks.
thumbnail
Tanweer Ahmed ., modificado hace 1 año.

RE: Embed web content into theme (freemarker - ftl)

Expert Mensajes: 322 Fecha de incorporación: 11/03/10 Mensajes recientes
Hi Traolly,

WebContent Portlet is an instanceable Portlet i.e. everytime you drop it on a Layout, it will have a different instanceId.
You can get this id from the configuration section of the selected web content.
Regarding theme.journalArticle(), the same is successfully tested in LR 6.2 ftl theme.

- Tanweer
Traolly Xiong, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

Regular Member Mensajes: 195 Fecha de incorporación: 30/12/11 Mensajes recientes
Hello ,
I've tried the below ....

${theme.journalArticle("15028", "10580","14260")}

web content id: "15028"
scope id: "10580"
template id: "14260"

.... to get the selected web content to display in the embedded portlet within the theme and I got the error below....

10:22:02,084 ERROR [http-bio-80-exec-17][runtime:96] Template processing error: "Method public void com.liferay.taglib.util.VelocityTaglibImpl.journalArticle(java.lang.String,long,java.lang.String) throws java.lang.Exception threw an exception when invoked on com.liferay.taglib.util.VelocityTaglibImpl@1fc44bba"

Method public void com.liferay.taglib.util.VelocityTaglibImpl.journalArticle(java.lang.String,long,java.lang.String) throws java.lang.Exception threw an exception when invoked on com.liferay.taglib.util.VelocityTaglibImpl@1fc44bba
The problematic instruction:
----------
==> ${theme.journalArticle("15028", "10580","14260")} [on line 39, column 33 in QAD.com-theme_SERVLET_CONTEXT_/templates/footer.ftl]
in include "${full_templates_path}/footer.ftl" [on line 76, column 25 in QAD.com-theme_SERVLET_CONTEXT_/templates/portal_normal.ftl]
....


I've already set the below parameters in the properties file:

journal.template.freemarker.restricted.variables=
freemarker.engine.restricted.classes=
freemarker.engine.restricted.variables=

I'm on Liferay 6.2 sp8. Any ideas why the Velocity error is happening?

Thanks.
Traolly Xiong, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

Regular Member Mensajes: 195 Fecha de incorporación: 30/12/11 Mensajes recientes
If this helps, if given the actual journalArticle object, which ftl api would I need to render it within the theme onto the page?

ex)
<#assign webContentURLTitle = "abc">
<#assign journalArticle = journalArticleLocalService.getArticleByUrlTitle(groupid, webContentURLTitle)>



Thanks.
thumbnail
Tanweer Ahmed ., modificado hace 1 año.

RE: Embed web content into theme (freemarker - ftl)

Expert Mensajes: 322 Fecha de incorporación: 11/03/10 Mensajes recientes
Hi Traolly,

From the logs it is clear that the method journalArticle() expects the second parameter of type long and you are passing it as String.
And this is causing the Exception.

-Tanweer
Traolly Xiong, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

Regular Member Mensajes: 195 Fecha de incorporación: 30/12/11 Mensajes recientes
Good eye Tanweer.

Few questions if you don't mind.

1) I cannot find any documentation on the Liferay available "theme" apis. Can you or anyone point in the right direction?

ex) ${theme.<method api call>(.....)}

2) ${theme.runtime(<portlet ID>, "", "")} method

When constructing the portlet ID (i.e. "<portlet id> + _INSTANCE_ + <instance id>"), I was thinking to use the web content id for the "instance id", but
it would seem the article below says one can make up a 4 char alphanumeric string. What instance id did you use?

ex) porltet id: "58_INSTANCE_4gtH"
- https://www.liferay.com/community/wiki/-/wiki/Main/Embedding+a+portlet+in+the+theme#section-Embedding+a+portlet+in+the+theme-Step+One:+Obtain+the+portlet+nomenclature
- https://www.liferay.com/community/wiki/-/wiki/Main/Theme+Id+or+Portlet+Id+references+in+portal-ext.properties

ex) Very similar to the velocity way of doing this, the freemarker code below does not work:

........

<#assign webContentURLTitle = "Footer Links">
<#assign instance_id2 = "4gtH">
<#assign groupid = themeDisplay.getScopeGroupId()>
<#assign journalArticleLocalService = serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService")>
<#assign webContentURLTitle = stringUtil.lowerCase(webContentURLTitle)>
<#assign webContentURLTitle = stringUtil.replace(webContentURLTitle, " ", "-")>
<#assign webContentURLTitle = stringUtil.replace(webContentURLTitle, "--", "-")>
<#assign journalArticle = journalArticleLocalService.getArticleByUrlTitle(groupid, webContentURLTitle)>
<#assign portlet_id = "56">
<#assign my_portlet_id = portlet_id + "_INSTANCE_" + instance_id2>
<#if journalArticle>
<br>
<h1>Found Journal Article!!!: </h1>
${journalArticle.getTitle("en_US")}
<br>
${theme.runtime(my_portlet_id, "", "")}
</#if>

................

3) ${theme.journalArticle("10580", 10584, "14260")} method

It appears after passing it the needed long value it does nothing and does not display a portlet like the above #2) method call.

What am I missing here?



Any other helpful info on how to render a pre selected web content in a portlet embedded within a theme (via freemarker) is fully appreciated.

Thanks.
thumbnail
Tanweer Ahmed ., modificado hace 1 año.

RE: Embed web content into theme (freemarker - ftl)

Expert Mensajes: 322 Fecha de incorporación: 11/03/10 Mensajes recientes
Hi Traolly,

Look into the class VelocityTaglibImpl to know more about the methods.

Regarding the fully qualified PortletId which is a combination of (PortletId_INSTANCE_instanceId), the last part which is instanceId will be different for each of the webcontent portlet.
You must get the complete Portlet Id from the Configuration section of your specific WebContent Portlet.
Look for the Portlet ID text into the Configuration section.Use the same portletId in your themes.

-Tanweer
Traolly Xiong, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

Regular Member Mensajes: 195 Fecha de incorporación: 30/12/11 Mensajes recientes
- So I'm on the same page, is it your understanding that the web content is pre-populated or does one have to manually select it?

- As you stated the api method below doesn't seem to be working as you think it may be a bug. It allows the portlet to render but it forces you to
select / add a web content.

"${theme.runtime(my_portlet_id, "", "")}"

- For the "journalArticle" api method call below, it's a void method that invokes other classes under the package below.

ex #3 above post) ${theme.journalArticle("10580", groupid, "14260")}

https://github.com/liferay/liferay-portal/tree/master/util-taglib/src/com/liferay/taglib/util

It displays nothing on the page. Do you have a working snippet that I can try?

Thanks.
Tomas Augustaitis, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

New Member Mensajes: 6 Fecha de incorporación: 15/10/13 Mensajes recientes
To display Web Content I use this code:


&lt;#assign journalArticleLocalService = serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService") &gt;
&lt;#assign footerContent= journalArticleLocalService.getLatestArticleByUrlTitle(themeDisplay.getScopeGroupId(), "footer-content", 0)&gt;
${journalContentUtil.getContent(groupId, footerContent.getArticleId(), "", locale.toString(), themeDisplay)}


where "footer-content" is Title of the Web content.
Traolly Xiong, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

Regular Member Mensajes: 195 Fecha de incorporación: 30/12/11 Mensajes recientes
Thanks Thomas. I've already got it working with this code snippet:

<#assign locPortletId = "56_INSTANCE_1TRX" />
<#assign PortletPreferencesFactoryUtil = staticUtil["com.liferay.portlet.PortletPreferencesFactoryUtil"] />
<#assign portletSetup = PortletPreferencesFactoryUtil.getLayoutPortletSetup(layout, locPortletId) />
<#if portletSetup.getValue("portletSetupShowBorders", "") != "false" >
<#assign temp = portletSetup.setValue("portletSetupShowBorders", "false") />
<#assign temp = portletSetup.setValue("groupId", "10584") />
<#assign temp = portletSetup.setValue("articleId", journalArticle.getArticleId()) />
<#assign temp = portletSetup.store() />
</#if>

${theme.runtime(locPortletId, "", portletSetup.toString())}


Only difference between yours and mine is that mine displays the actual portlet with configurations to edit / edit template / select / add web content
and yours only renders that content with in the them.

Thanks for the help everyone and I hope this helps others.

Regards,
Traolly Xiong
thumbnail
Sarah L Farley, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

Junior Member Mensajes: 37 Fecha de incorporación: 6/05/09 Mensajes recientes
Hi Tomas,

I have the following in my init_custom.vm

#set($footerContentTitle = $theme_display.getThemeSetting("Footer Content Article Title"))
#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleService"))
#set($footercontentarticle = $journalArticleLocalService.getArticleByUrlTitle($group_id, $footerContentTitle))
#set ($footercontent = $footercontentarticle.getContent())


Within my portal_normal.vm I have:

<div class="row-fluid deptfooter">
$footercontent
 </div>


When I deploy my theme all that I see is $footercontent, not the actual content of the journal article. Do you have any suggestions? I am on 6.2.

Thanks!
Sarah
thumbnail
Juan Víctor Martínez, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

New Member Mensajes: 19 Fecha de incorporación: 18/03/11 Mensajes recientes
Sarah L Farley:
Hi Tomas,

I have the following in my init_custom.vm

#set($footerContentTitle = $theme_display.getThemeSetting("Footer Content Article Title"))
#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleService"))
#set($footercontentarticle = $journalArticleLocalService.getArticleByUrlTitle($group_id, $footerContentTitle))
#set ($footercontent = $footercontentarticle.getContent())


Within my portal_normal.vm I have:

<div class="row-fluid deptfooter">
$footercontent
 </div>


When I deploy my theme all that I see is $footercontent, not the actual content of the journal article. Do you have any suggestions? I am on 6.2.

Thanks!
Sarah


I have the same problem. How can I solve this?
thumbnail
Sarah L Farley, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

Junior Member Mensajes: 37 Fecha de incorporación: 6/05/09 Mensajes recientes
converting your string for the journal article title to lowercase.


#set($footerContentTitle = $theme_display.getThemeSetting("Footer Content Article Title").toLowerCase())
#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleService"))
#set($footercontentarticle = $journalArticleLocalService.getArticleByUrlTitle($group_id, $footerContentTitle))

## get content for article id
#set ($articleContent = $journalContentUtil.getContent($themeDisplay.getScopeGroupId(), $footercontentarticle.getArticleId(), null, $locale.toString(), $themeDisplay))
thumbnail
Juan Víctor Martínez, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

New Member Mensajes: 19 Fecha de incorporación: 18/03/11 Mensajes recientes
Hi Sarah, thank so much for your response, but did not work for me.
the $footerContentTitle, $footercontentarticle and $articleContent not receive value.

I tried with:

init_custom.vm

#set ($local_temp_content = $journalContentUtil.getContent($scope_group_id, "Web content Id", null, "$locale", $theme_display))


portal_normal.vm

$local_temp_content


But $journalContentUtil.getContent() does not work.
thumbnail
Juan Víctor Martínez, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

New Member Mensajes: 19 Fecha de incorporación: 18/03/11 Mensajes recientes
Resolved!

I used this function: glarticle
thumbnail
Daniel Tyger, modificado hace 9 años.

RE: Embed web content into theme (freemarker - ftl)

Regular Member Mensajes: 105 Fecha de incorporación: 6/02/13 Mensajes recientes
Juan Víctor Martínez:
Resolved! I used this function: glarticle

Hi Sarah and Juan and others: I obsessed on this topic for some time and finally have something I am comfortable with that does not require the macro or other theme.runtime nor service locator juju... (this is working in Liferay 6.2[ee]:

In liferay-look-and-feel.xml:
			  <setting configurable="true" key="footer-section-article-id" type="text" value="" />


In init_custom.vm of the theme /diffs...:
## Footer article option via L n F settings...##
#if ( "$theme_settings.footer-section-article-id" != "" )
#set ($footer_section = $journalContentUtil.getContent($group_id, $theme_settings.footer-section-article-id, null, "$locale", $theme_display))
#end


and in portal_normal in the footer section, I used this:
<footer id="footer" role="contentinfo">
		#if ( "$theme_settings.footer-section-article-id" != "" )
			$footer_section
		#else
			<p style="text-align: center;">For assistance, contact the 
			<a href="/group/mycampus/technology-support-center">Support Center</a>.</p>
		#end
	</footer>


I hope it helps others!
Gustavo Segovia, modificado hace 7 años.

RE: Embed web content into theme (freemarker - ftl)

New Member Mensajes: 4 Fecha de incorporación: 6/09/16 Mensajes recientes
In case you know your article id and you are using liferay 7, this works:

&lt;#assign journalArticleLocalService = serviceLocator.findService("com.liferay.journal.service.JournalArticleLocalService")&gt;
&lt;#assign article = journalArticleLocalService.fetchArticle(group_id, "FOOTER")&gt;
${journalArticleLocalService.getArticleContent(article, article.getDDMTemplateKey(), "VIEW", locale, themeDisplay)}
thumbnail
Abhishek Jain, modificado hace 6 años.

RE: Embed web content into theme (freemarker - ftl)

Regular Member Mensajes: 226 Fecha de incorporación: 20/08/16 Mensajes recientes
thanks Gustavo, it helped..
Aitor Gonzalez Sanz, modificado hace 6 años.

RE: Embed web content into theme (freemarker - ftl)

New Member Mensajes: 2 Fecha de incorporación: 4/01/18 Mensajes recientes
Hi all!

First of all thanks for all the help you provide here.

I have a questions and i am not able to come across a solution. The issue is that i need to embed a web content from a theme, but i need to specify which template have to be used by the web content.

I know that i can select which template a web content use throught the configuration of web content displayer, but I really need this one to be embeded from a theme.

Thanks for all!! Keep it up!