Developer forum

Forum » Development » NavigationProvider: Remove menus?

NavigationProvider: Remove menus?

Jonas Kæseler
Reply
Hi,

I have a eCom group based navigation and I need to remove/hide menus for certain logged in users.
The Dynamicweb.Frontend.NavigationProviders.NavigationItem class seems to be missing methods for doing this directly.

What is the best approach then?

Rebuilding the entire group tree to match the specific user seems a little silly...

Best regards
Jonas

Replies

 
Yury Zhukovskiy
Reply

Hi, I think the best solution is changing xslt for the menu.

Navigation XML contains information about logged in user: Global.Extranet.UserID tag, Global.Extranet.Groups tag, etc. So you can configure rule to display or hide some navigation items based on logged in user.

To see all available tags execute http://yoursite/Admin/Public/GetNavigationXML.aspx

 

Otherwise you have to implement own navigation provider:

http://developer.dynamicweb-cms.com/Forum.aspx?PID=48&ThreadID=23903

http://devierkoeden.com/articles/extending-the-sitemap-with-dynamicweb-content.aspx

 

try to search in the forum:

http://developer.dynamicweb-cms.com/Search.aspx?q=Navigation

 

 

Kind Regards

Zhukovskiy Yury

 
Jonas Kæseler
Reply

Hi Yury
Thanks for the quick reply

Hi, I think the best solution is changing xslt for the menu.

I can't really do this since the removed groups is different from user to user and it's all based on a database call.

 

Otherwise you have to implement own navigation provider:

http://developer.dynamicweb-cms.com/Forum.aspx?PID=48&ThreadID=23903

http://devierkoeden.com/articles/extending-the-sitemap-with-dynamicweb-content.aspx

My thoughts too and I actually did that. However I can't remove the menu items - only add new ones and change the existing. 
Of course, I could rebuild the entire tree from scratch by adding only the allowed groups but it seems stupid since the majority of the DW standard output is OK.

Best regards
Jonas
 

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply
This post has been marked as an answer
Hi Jonas,

You can certainly remove items. Each item has a ChildNodes collection which in turn has a Remove method.

For example:

rootNode.ChildNodes.Remove(item);

Just make sure you loop over the child items in reversed order instead of using a foreach or regular for loop as you can't modify the collection while iterating over it.. Here's a quick example that looks for an item based on its MouseOver (which I abused as some tag), stores the item in a variable for later use and then removes it from the tree:
for (int i = rootNode.ChildNodes.Count - 1; i >= 0; i--)
{
	PageNavigationItem item = rootNode.ChildNodes[i] as PageNavigationItem;
	if (item != null)
	{
		switch (item.MouseOver)
		{
			case "ShopRoot":
				shopRoot = item;
				rootNode.ChildNodes.Remove(item);
				break;
			default:
			  break;
		}
	}
}

Hope this helps,

Imar

Votes for this answer: 0
 
Jonas Kæseler
Reply
Hi Imar,

Thanks for the point about the iteration. I was stuck in a foreach.

Seems to be just what I needed :)

Jonas

 

You must be logged in to post in the forum