December 12, 2011

Embed web content in theme- Liferay6.X.X

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" "http://www.liferay.com/dtd/liferay-look-and-feel_5_0_0.dtd">

<look-and-feel>
    <compatibility>
        <version>6.0.0+</version>
    </compatibility>
   <company-limit>
        <company-includes />
        <company-excludes />
   </company-limit>
    <theme id="drupal-garland" name="drupal-garland">
        <template-extension>vm</template-extension>
    <settings>
          <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" />
  </settings>
 </theme>
</look-and-feel>

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))
    #end

    $!{temp_content}
#end

1 Discussion: