Umbraco-CMS: v8: Missing extension methods to get siblings

In v8 it seems IPublishedContent is missing extension methods to get sibling node, e.g. sibling of type or siblings of any type.

You can use e.g. node.Parent.Children() or node.Parent.ChildrenOfType() of do some querying on this, but it won’t work if the node is under root level, so it hasn’t any parent node.

In v7 there are many extension methods for these.

.Sibling()
.Siblings()
.Siblings<T>()

.PrecedingSibling()
.PrecedingSibling<T>()

.FollowingSibling()
.FollowingSibling<T>()

.Previous()
.Previous<T>()

.Next()
.Next<T>()

In v8 we should probably have extension method as .Sibling(), .Sibling(), SiblingsOfType() like we have e.g, .ChildrenOfType().

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (19 by maintainers)

Most upvoted comments

I have updated the PR to contain both Siblings and SiblingsAndSelf. I added remark to the Siblings XMLDoc about the difference compared to V7.

@bergmania As you mention earlier, the node itself usually gets rendered differently and we already have it anyway (otherwise we cannot call .Siblings() or .ParentChildren() on it), so I do not see why it should be returned again.

Off the top of my head I can imagine a scenario where the node itself gets rendered as the main thing, and then there is a list of siblings() for further navigating, e.g.:

@* Main Content *@
<h2>@Model.Content.Title</h2>
<img src="@Model.Content.Image.Url" />

@* Siblings *@
<h3>Related items:</h3>
<ul>
@foreach(var sibling in Model.Content.Siblings()) 
{
    <li><a href="@sibling.Url">@sibling.Title</a></li>
}
</ul>

I’m sure there are plenty of other use cases.