Umbraco 从子页面获取内容

Umbraco get content from child pages

有没有办法将 x 个子页面的内容渲染到它们的父页面上? 我使用的是 Umbraco 7,我不太擅长剃须刀。

这是我的尝试,在 umbraco 论坛的一个未回答的 post 上找到: (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")

不努力。 错误:无法将类型 'Umbraco.Core.Dynamics.DynamicNull' 隐式转换为 'Umbraco.Core.Models.IPublishedContent'.

感谢您的支持。

约翰

Umbraco.Contentreturns一个动态。您需要为第一行尝试获取 IPublishedContent:

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

问题是 x.IsVisible() 不起作用,所以您需要使用:

x.GetPropertyValue<bool>("isVisible")