(888) 685-3101 ext. 2

I recently came across a situation where the requirement was to create some navigation in a theme that spans communities.  This is something that you would normally want to just hardcode in the links and move on to the next task.  This scenario was different because the admin team wanted to leverage Liferay’s permissioning model so they could restrict who had access to the links.  Since there were so many unknowns as to how the portal would grow and be leveraged, I decided to take advantage of a couple features that are new in Liferay v6.

WCM Modifications

The basic solution starts by creating a structure and template in Liferay’s WCM.  I created these artifacts in Liferay’s new Global content repository / library and used them to create the links that would show up in the navigation.  In my case, the links went to a different server altogether.

The Structure (GLOBAL-NAV-LINK-STRUCTURE)

<root>
<dynamic-element name="label" type="text" index-type="" repeatable="false"/>
<dynamic-element name="target" type="list" index-type="" repeatable="false">
<dynamic-element name="_self" type="_self" index-type="" repeatable="false" />
<dynamic-element name="_parent" type="_parent" index-type="" repeatable="false"/>
<dynamic-element name="_top" type="_top" index-type="" repeatable="false"/>
<dynamic-element name="_blank" type="_blank" index-type="" repeatable="false"/>
</dynamic-element>
<dynamic-element name="style" type="text" index-type="" repeatable="false"/>
<dynamic-element name="href" type="text" index-type="" repeatable="false"/>
<dynamic-element name="alt" type="text" index-type="" repeatable="false"/>
</root>

The Template (GLOBAL-NAV-LINK-TEMPLATE)

<a href="$href.getData()"
style="$style.getData()"
target="$target.getData()"
alt="$alt.getData()"><span>$label.getData()</span></a>

Custom Fields Modifications

Once the content items were created, I added three custom variables to the Page object in the Control Panel.

Control Panel > Portal > Custom Fields > Page

Custom-Fields-Modifications

NOTE: It could be possible that your ID for the Global repository is different, so you should verify it if you plan to use this method of embedding content in the Liferay theme.

Theme Changes

Smaller bits of code are generally easier to understand and maintain.  Rather than adding several lines of code to the existing files in the theme, I created a new file in the _diffs directory and added the appropriate reference in the navigation.vm file.

custom-navigation.vm

#set( $sid = $theme_display.getLayout().getExpandoBridge().getAttribute("structure-id") )
#set( $tid = $theme_display.getLayout().getExpandoBridge().getAttribute("template-id") )
#set( $gid = $getterUtil.getLong($theme_display.getLayout().getExpandoBridge().getAttribute("global-group-id") ) )
#set( $approved = $getterUtil.getInteger("0"))#set( $journalArticleLocalService = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleLocalService") )
#set( $articles = $journalArticleLocalService.getStructureArticles( $gid, $sid ) )#foreach( $article in $articles )
#if( $article.getStatus() == $approved && $journalArticleLocalService.isLatestVersion($gid, $article.getArticleId(), $article.getVersion(), $article.getStatus()) )
<li>$journalArticleLocalService.getArticleContent($article,$tid,"","",$theme_display)</li>
#end
#end

Permission Changes

The final step is to modify the roles so they can view the custom attributes on the Page object.  I will show you how to do that on the Guest role, but you will probably want to do this for the User and/or Power User role depending on how you are setup.

Control Panel > Portal > Roles > Guest > Actions > Define Permissions

Permission-Changes

Save your changes and you are good to go.  Now you can embed WCM content in a Liferay v6 theme!

Share This