Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Add a episerver menu (menu tree) to a BlockType

Vote:
 

i have a requirement to add a full episerver menu tree in a block type..if i add a new page in menu it should reflect in blocktype also.

#151384
Jul 19, 2016 14:01
Vote:
 

Hi.

Can you try and be a bit more specific? Do you need a visual representation of the Episerver page-tree in a BlockType - e.g. for end user navigation purposes?

Casper Aagaard Rasmussen

#151385
Jul 19, 2016 14:16
Vote:
 

yes exactly...i want a Episerver PageTree in BlockType..if i add new PageType in PageTree it should automatically get reflect in blockType

#151386
Jul 19, 2016 14:55
Vote:
 

Hi.

You need to build the logic to support that requirement. It would make sense to build some recursive logic that uses the IContentRepository's GetChildren and Get<> methods. It enables you to recursively work your way through your Episerver page tree - hint: start with ContentReference.StartPage and work down from that.

Please be aware that it potentially can get costly dependent on your page tree depth. Often, what I see is the need to list all nodes (pages in your context) beneath current page in order to provide navigation options to end users. To do this, you need to use the PageRouteHelper to access the current page your Block is currently used on. That will give you the context. 

All above mentioned stuff has to be executed in the Controller belonging to your BlockType. I'm assuming you use MVC.

Hope that helped you to move forward.

Maybe you can get inspired by this code that I made on the fly. Be aware that it's not tested and only acts as a simplified example of how to interact with IContentRepository. It gives you the recursive feature but does not build the tree-structure.

public class ContentHelper
	{
		private readonly IContentRepository _contentRepository;

		public ContentHelper()
		{
			this._contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>();
		}

		public void FindDescendantsOfType<T>(ContentReference reference, ICollection<T> descendants) where T : PageData
		{
			var children = this._contentRepository.GetChildren<T>(reference);
			foreach (var child in children)
			{
				descendants.Add(child);

				FindDescendantsOfType(child.ContentLink, descendants);
			}
		}
	}

Casper Aagaard Rasmussen

#151392
Jul 19, 2016 21:12
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.