0
votes

Is there a way to render the content of x child pages onto their parent page? Im using Umbraco 7 and im not very good with razor.

This is my attempt, found on an unanswered post in the umbraco forum: (https://our.umbraco.org/forum/umbraco-7/using-umbraco-7/60936-Grid-on-CurrentPage-Children)

IPublishedContent currentPage = Umbraco.Content(CurrentPage.Id);
IEnumerable<IPublishedContent> children = currentPage.Children().Where(x => x.IsVisible());

foreach(var child in children){
@child.GetGridHtml("grid")

Doesnt work tough. Error: Cannot implicitly convert type 'Umbraco.Core.Dynamics.DynamicNull' to 'Umbraco.Core.Models.IPublishedContent'.

Thanks for your support.

John

1

1 Answers

1
votes

Umbraco.Content returns a dynamic. You need to get the IPublishedContent for the first line try:

IPublishedContent currentPage = Umbraco.TypedContent(CurrentPage.Id);

The problem then is x.IsVisible() doesn't work so you need to use:

x.GetPropertyValue<bool>("isVisible")