« Back

Static Navigation for Liferay Portal

General Blogs June 28, 2013 By priti parmar

create a ServicePreAction, which will create a new
custom NavItem object and a change in navigation.vm of the theme, which
will show the custom navigation.


Here are the steps to create the custom navigation


1) Create a new ServicePreAction hook
2) In the run() method of ServicePreAction, retrieve the your community
group object


ThemeDisplay themeDisplay = (ThemeDisplay)
req.getAttribute(WebKeys.THEME_DISPLAY);
Group baseCommunity = GroupLocalServiceUtil.getGroup(themeDisplay.getCompanyId(), "yourcommunitName");
long defaultLayoutId = LayoutLocalServiceUtil.getDefaultPlid(baseCommunity.getGroupId());
Layout defaultLayout = LayoutLocalServiceUtil.getLayout(defaultLayoutId);
List<Layout> layoutSet = LayoutLocalServiceUtil.getLayouts(baseCommunity.getGroupId(), false);
List<Layout> publicNonHiddenLayouts = newArrayList<Layout>(layoutSet.size());
for(Layout layout:layoutSet) {

    if(!layout.isHidden() && layout.getParentLayoutId()==0)
    {
         publicNonHiddenLayouts.add(layout);
    }
}
RequestVars requestVars = new RequestVars(req,themeDisplay,
defaultLayout.getAncestorPlid(), defaultLayout.getAncestorLayoutId());
List navItems = NavItem.fromLayouts(requestVars,publicNonHiddenLayouts);
Map vmVariables = new HashMap();
vmVariables.put("baseNavItems", navItems);
req.setAttribute(WebKeys.VM_VARIABLES, vmVariables);
---------------------------------------------------------------------------------------
Now, in the navigation.vm of the Theme,
replace  #foreach ($nav_item in $nav_items)  with  #foreach ($nav_item in $baseNavItems)

Threaded Replies Author Date
[...] Static Navigation for Liferay Portal -... Anonymous July 3, 2013 7:22 AM

[...] Static Navigation for Liferay Portal - Blog - Liferay.com [...] Read More
Posted on 7/3/13 7:22 AM.