Your most unhappy customers are your greatest source of learning.

Embed web content in theme- Liferay6.X.X

December 12, 2011

Hello Liferay folks,

I know that many time you will have this requirement that you need to integrate web content into Liferay theme.
So here is the code which can help you to integration :

Please follow the below steps :

1) Create theme in liferay
2) create liferay-look-and-feel.xml and put below code:
     <?xml version="1.0"?>
<!DOCTYPE look-and-feel PUBLIC "-//Liferay//DTD Look and Feel 5.0.0//EN" "">

        <company-includes />
        <company-excludes />
    <theme id="drupal-garland" name="drupal-garland">
          <setting key="portlet-setup-show-borders-default" value="false" />
          <setting key="header-article-id" value="header-article-id" />
          <setting key="sidebar-article-id" value="sidebar-article-id" />
          <setting key="footer-article-id" value="footer-article-id" />

3) Now put the below code in .vm file where you want to show that web content.
    #set ($portletSetupShowBordersDefault = $theme_settings.getProperty("portlet-setup-show-borders-default"))

#set ($journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService"))

#set ($headerArticleId = $theme_settings.getProperty("header-article-id"))
#set ($journalArticleContentObject = $journalArticleLocalService.getArticleByUrlTitle( $theme_display.getCompanyGroupId(), $headerArticleId))
#set ($templateId = $journalArticleContentObject.getTemplateId())
#set ($headerContent = $journalContentUtil.getContent( $theme_display.getCompanyGroupId(), $journalArticleContentObject.getArticleId(), $templateId, "$locale", $theme_display))

<div id="header">$headerContent</div>

4) Don't wait for next steps guys !!!! you are done with the functionality.
This is the easiest way to integrate the web content in theme.

One more way to do that using below code:

#macro(glarticle $temp_article_id)

    #set ($temp_content = "")

    #set ($scope_group_id = $theme_display.scopeGroupId)
    #set ($global_group_id = $theme_display.companyGroupId)

    #set ($temp_content = $journalContentUtil.getContent($scope_group_id, $temp_article_id, null, "$locale", $theme_display))
    #set ($temp_content = "$!{temp_content}")

    #if ($temp_content.length() == 0)
        #set ($temp_content = $journalContentUtil.getContent($global_group_id, $temp_article_id, null, "$locale", $theme_display))

Post a Comment