Try our conversational search powered by Generative AI!

What I have to expect from GetChildren


I'm not sure. 

But, when I use GetChildren is it return blocks and pages or just pages?

in this particular code:

var hasChildren = _contentLoader.GetChildren(content.ContentLink).Any();

I'm getting 3 elements, 1 page, and 2 blocks. 

I checked the parentLink is correct. But I have no idea how this was related to this page.

Dec 15, 2016 6:28

If you just like pages you should got with GetChildren<PageData> or for blocks just BlockData. Or you can use your own pagetype or blocktype as well. You do not need .Any() either. Not sure why it returns blocks as well in your case. Need more information but my guess is that the IContent is causing this.

Do you have any blocks on the page? Block also is structured the same way if you look in adminmode and access rights you will be able to see all content and not anly pages is structured the same way.

Dec 15, 2016 14:17

Ah sorry Any() is needed for you i guess since you are working with hasChildren :) 

Dec 15, 2016 14:18

Any IContent, blocks, pages, media. If you need just pages, you can use OfType<PageData>() after GetChildren.



Dec 15, 2016 21:02

This page has some blocks on Content Area. 

The blocks on Content aren't showing as a Children. I can't find where was add this blocks as children of this page.

On the tree is just on page as children and the same is showing on Access Rights.

Looking to the DataBase these blocks are children of this page. The getChildren are working perfectly. 

What would I like to understand is how is possible to add a block as children of a page? 

Edited, Dec 16, 2016 1:50

Ah,OK, I wasn't sure what you were aiming for. They are probably not children of the page, but rather either somewhere in the Blocks folder structure (a folder is their parent) or they are placed in the folder "For this page". Again, the folder is the parent, so you won't get them with get children from the page itself.

You should get them by fetching FilteredItems from the content area instead.



Dec 16, 2016 8:05

To add blocks as children of the page, you'd need to do it programmatically, by setting the page as their parent.

Dec 16, 2016 8:06

Might be better to write the usecase - what you want to achieve from user/editor perspective.

Dec 16, 2016 8:08

In this case, I have this blocks just in production. It means that was added by the content team and not from code behind. 

Jan 09, 2017 0:16
* 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.