Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Andy Harb
Limit navigation items based on roles/groups
March 30, 2010 3:28 PM
Answer

Andy Harb

Rank: Junior Member

Posts: 66

Join Date: October 22, 2009

Recent Posts

I have developed my own navigation menu which works great. It displays exactly as I would expect and hides the navigation items when the "Hidden" box is checked on the page settings. However, what I would like to implement next is limiting what the users can see based on their roles.

Over simplified version of what I'm doing.
1#foreach ($nav_item in $nav_items)
2    <li>$nav_item.getName()</li>
3  #end


This will display all the top level navigation items in the community. However, lets say I have a top level navigation item called "Members" that I want only users who are permission to view it to see. Is there a way to return back only the children nav items or layout that the current user is permission to view? So in the example given if I wasn't logged in i wouldn't see the "Members" item listed.
Oliver Bayer
RE: Limit navigation items based on roles/groups
March 31, 2010 2:16 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 889

Join Date: February 18, 2009

Recent Posts

Hi Andy,

maybe you can use $permissionChecker.hasPermission(...) inside the foreach loop to check for view rights. Use AktionKeys.<right> e.g. ActionKeys.VIEW.

Oli
Andy Harb
RE: Limit navigation items based on roles/groups
April 1, 2010 7:58 AM
Answer

Andy Harb

Rank: Junior Member

Posts: 66

Join Date: October 22, 2009

Recent Posts

Thanks Oli,

So I played around with it more and found out that the $navItems variable available in the theme returns what you would expect in terms of permissions & view controls.

The problem I was having was in the Layout Management section when i was using the $layout variable. The $layout.getChildren() will return all the navigation items regardless of permissions. Where as the $navItems.getChildren() will return only children that are visible to the current user.

Does anyone know if there is a way to grab the current Navigation Item based on the page you are on? This way i can build out the sub-navigation based off it.


Edit:
Solution
1$layout.getChildren($permissionChecker)
Pilar Hidalgo
RE: Limit navigation items based on roles/groups
September 25, 2012 1:20 AM
Answer

Pilar Hidalgo

Rank: New Member

Posts: 14

Join Date: April 10, 2012

Recent Posts

Hi,

I have the same problem.. where goes the code of your solution? thanks!
Oliver Bayer
RE: Limit navigation items based on roles/groups
October 11, 2012 1:02 AM
Answer

Oliver Bayer

Rank: Liferay Master

Posts: 889

Join Date: February 18, 2009

Recent Posts

Hi Pilar,

the mentioned code snippet should be put in your custom theme e.g. into the navigation.vm.

HTH Oli

Participate in the State of Liferay Community 2017. Help the community and even win some prizes!