Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
AI OnAI Off
Five New Optimizely Certifications are Here! Validate your expertise and advance your career with our latest certification exams. Click here to find out more
Try child.ContentLink
You can also use GetDescendants (not cached). Depends what you are trying to do...
Thanks Aniket. I'm not seeing a ContentLink property via Intellisense or the documentation. Errors that I'm seeing when attempting that are in the comments below.
foreach (ContentData child in contentDataList)
{
var x = child.ContentLink; // Cannot assign method group to an implicitly-typed variable.
List<ContentData> children = contentLoader.GetChildren<ContentData>(child.ContentLink); // Cannot convert from 'method group' to 'ContentReference'
}
Where is the GetDescendants method for that? I don't see that either. Do I need to cast that ContentData child object first?
What I'd like to do is get the descendants of that ContentData child object. Thanks.
So I'm trying to build a recursive tree of ContentData objects starting from the ContentReference.RootPage. I'm working in EPiServer 8. It looks like the IContentLoader method GetChildren would do the trick, but it's only allowing me to send a ContentReference to the GetChildren argument.
If I knew how to convert a ContentData object to a ContentReference object, I could probably make this work. But I don't know if that's possible. Here is my latest attempt.
// These 3 lines do what I expect. IContentLoader contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>(); List<ContentData> contentDataList = contentLoader.GetChildren<ContentData>(ContentReference.RootPage).ToList(); ContentData rootContentData = (ContentData)ServiceLocator.Current.GetInstance<IContentRepository>().Get<IContent>(ContentReference.RootPage); foreach (ContentData child in contentDataList) { // This next line fails with the error: Cannot convert from 'EPiServer.Core.ContentData' to 'EPiServer.Core.ContentReference' List<ContentData> children = contentLoader.GetChildren<ContentData>(child); //ContentReference childRef = (ContentReference)child; // Nope //ContentReference childRef = child as ContentReference; // Nope }
How can I get the children of a ContentData object? Thank you.