Umbraco-仅获取文档类型的子元素



我在下面有一个结构链接

pageone

  • - columnitem-one

    - columnitems-two

    - columnItems-three

    - columnitems-four

pagetwo

  • - columnitems-oneb

    - columnitems-twob

我有一个部分视图,我想显示每个儿童列项目,但是目前我正在使用的后代,该后代正在返回所有6个项目,而不是在Pageone上返回4个项目,而Pagetwo上的2个项目。

我的代码是

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    var root = Model.Content;
    var tiles = root.Descendants("tiles");

    if(tiles.Count() > 0)
    {
        <div class="row tile-row">
            @foreach(var node in tiles)
            {
                <div class="col-md-3">
                    <div class="tile">
                        <h3>@(node.GetPropertyValue("tileTitle"))</h3>
                        @(node.GetPropertyValue("tileBodyText"))<br/>
                        <a class="btn btn-more" href="@(node.GetPropertyValue("tileButtonLink"))">@(node.GetPropertyValue("tileButtonText"))</a>
                    </div>  
                </div>
            }
        </div><!--/.row-->
    }
}

如果我将后代更改为儿童()我会收到一个错误页面。

thansk

如果从PageOnePageTwo调用部分视图,则可以使用强键入对象,可以执行以下操作:

@inherits Umbraco.Web.Mvc.UmbracoTemplatePage
@{
    // Get this PageOne or PageTwo object
    var page = Model.Content;
    // Get the column node that is descendant of this page
    var column = root.Descendants("columnAlias");
    // Get all children of the column node that are published
    var childs = column.Children.Where(x => x.IsVisible());
    if(childs.Count() > 0)
    {
        <div class="row tile-row">
            @foreach(var node in childs)
            {
                <div class="col-md-3">
                    <div class="tile">
                        <h3>@(node.GetPropertyValue("tileTitle"))</h3>
                        @(node.GetPropertyValue("tileBodyText"))<br/>
                        <a class="btn btn-more" href="@(node.GetPropertyValue("tileButtonLink"))">@(node.GetPropertyValue("tileButtonText"))</a>
                    </div>  
                </div>
            }
        </div><!--/.row-->
    }
}

相关内容

最新更新