For the complete documentation index, see llms.txt. This page is also available as Markdown.

IPublishedContent Collections

All collections of IPublishedContent are IEnumerable<IPublishedContent>. This means that all C# LINQ statements can be used to filter and query the collections.

Collections

.Children()

Returns a collection of child items available in the current culture, below the current content item.

<ul>
    @foreach(var item in Model.Children())
    {
        <li><a href="@item.Url()">@item.Name</a></li>
    }
</ul>

The Children property on IPublishedContent was removed in Umbraco 18. Use the Children() extension method instead.

.Children(string culture = null)

Returns a collection of child items available in the specified culture with a default of the current one, below the current content item.

<ul>
    @foreach(var item in Model.Children("dk-dk"))
    {
        <li><a href="@item.Url()">@item.Name</a></li>
    }
</ul>

.Ancestors()

Returns all ancestors of the current page (parent page, grandparent and so on)

.Ancestor()

Returns the first ancestor of the current page

.AncestorsOrSelf()

Returns a collection of all ancestors of the current page (parent page, grandparent and so on), and the current page itself

.Descendants()

Returns all descendants of the current page (children, grandchildren etc)

.DescendantsOrSelf()

Returns all descendants of the current page (children, grandchildren etc), and the current page itself

.OfTypes

Filters a collection of content by content type alias


Filtering, Ordering & Extensions

Filtering and Ordering are done with LINQ.

Some examples:

.Where

.OrderBy

.GroupBy

Groups collection by content type alias

.Take(int)

Return only the number of items for a collection specified by the integer value.

.Skip(int)

Return items from the collection after skipping the specified number of items.

You can combine Skip and Take when using for paging operations

.Count()

Returns the number of items in the collection

.Any()

Returns a boolean True/False value determined by whether there are any items in the collection

Filtering Conventions

Some filtering and routing behaviour is dependent upon a set of special naming conventions for certain properties. See also: Routing Property Conventions

.IsVisible()

If you create a checkbox property on a document type with an alias umbracoNaviHide then the value of this property is used by the IsVisible() extension method when filtering.

Use case: When displaying a navigation menu for a section of the site, following this convention gives editors the option to 'hide' certain pages from appearing in the section navigation. (hence the unusual umbracoNaviHide property alias!)

Last updated

Was this helpful?