AI OnAI Off
var contentTypeRepository = ServiceLocator.Current.GetInstance<IContentTypeRepository>(); var contentModelUsage = ServiceLocator.Current.GetInstance<IContentModelUsage>(); // loading a block type var contentType = contentTypeRepository.Load<CareerExplorerCareerProfilePage>(); // getting the list of block type usages, each usage object has properties ContentLink, LanguageBranch and Name var usages = contentModelUsage.ListContentOfContentType(contentType);
Other alternatives:
create a recursive method, something like:
protected static void GetDescendantsOfType<T>(PageData page, ICollection<T> descendants) where T : class { var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); var children = contentRepository.GetChildren<PageData>(page.ContentLink); foreach (var child in children) { if (child is T) { descendants.Add(child as T); } GetDescendantsOfType(child, descendants); } }
or use ContentRepository's GetDescendents and then filter by type etc:
var contentRepository = ServiceLocator.Current.GetInstance<IContentRepository>(); var descendants = contentRepository.GetDescendents(page.ContentLink);
I would recommend Daniels approach or to use FindPagesWithCriterion: https://github.com/alfnilsson/ascend2015/blob/master/Business/_StandardPageRepository/4%20FindPagesWithCriteria.cs
using getchildren or getdescendants requires the application to read the entire data structure which can be quite performance heavy.
Have a look at my blog post about good practices reading content from Epi https://talk.alfnilsson.se/2015/11/25/code-best-practices-and-performance-optimization-the-summary/
speciallt when considering cache and locks
Hi,
I would like to get all the pages of a particular Page type under a parent node. So far I use this code:
But it only bringing back the first child node pages. I would also like to bring back pages under the child - for example Grand Child.:
Top Node:
|_
CareerExplorerCareerProfilePage Page type (Child page)
|_
CareerExplorerCareerProfilePage Page type (Grand Parent)
I hope this makes sense,
Jon