Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Hi,
I think you've got a few options here and the correct one will depend on how your site is constructed and at what point you're planning to use the data.
I think the simplest route would be to use IContentLoader.GetDescendents(contenRef) to get a list of contentreferences of all content below the ContentReference you pass in. You can then loop through these and, for each one, use IContentLoader.Get<PageData>(ContentRef) to get the page. In this scenario I'd avoid getting all of the PageDatas in one go by doing something like IContentLoader.GetDescendents(contenRef).Select(x => contentLoader.Get<PageData>(ContentRef)) as you don't want to overload the server memory. Something like this:
var contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
var personalisedPages = new List<ContentReference>();
foreach (var pageRef in contentLoader.GetDescendents(SiteDefinition.Current.StartPage))
{
var page = contentLoader.Get<PageData>(pageRef);
var isPersonalised = page.Property.Any(p => ((p as IPersonalizedRoles)?.GetRoles().Any() ?? false) ||
(((p as PropertyContentArea)?.Value as ContentArea)?.Items?.Any(x => !string.IsNullOrEmpty(x.ContentGroup)) ?? false));
if (isPersonalised)
{
personalisedPages.Add(pageRef);
}
}
If this needs to be queried in response to a user request, you may be better adding the result of isPersonalised to a property indexed in Find then querying the data from Find instead of using IContentLoader.
Hi, I'm trying to list all pages that uses visitor groups, similar to this report: https://world.episerver.com/blogs/Paul-Smith/Dates1/2011/8/Visitor-Group-Usage-Report/
I tried this code which works with one page.
var page = contentRepo.Get<IContent>(ContentReference.Parse("9"));
var isPersonalised = page.Property.Any(p => ((p as IPersonalizedRoles)?.GetRoles().Any() ?? false) ||
(((p as PropertyContentArea)?.Value as ContentArea)?.Items?.Any(x => !string.IsNullOrEmpty(x.ContentGroup)) ?? false));
But I can't seem to find a way to get all pages and make it work.
I'm thinking something like this, if possible.
foreach (var page in pages)
{
var isPersonalised = page.Property.Any(p => ((p as IPersonalizedRoles)?.GetRoles().Any() ?? false) ||
(((p as PropertyContentArea)?.Value as ContentArea)?.Items?.Any(x => !string.IsNullOrEmpty(x.ContentGroup)) ?? false));
if (isPersonalised)
{
usedOnThesePages.Add(page);
}
}
Any suggestions?