V8.1 has seen the return of Siblings() and indeed SiblingsAndSelf()
Siblings will return the Siblings of the current item (but not the current item) and you guessed it SiblingsAndSelf() will include the current item too.
Next() and Previous() haven't been added back in however 'you could' create your own extension methods onto IPublishedContent to implement them, and now that we can easily get Siblings, it's quite straightforward. If you add something like the following to your projects:
var newsList = Model.Parent.Children("alias");
var currentIndexInNewsList = newsList.FindIndex(x => x.Id == Model.Id);
var totalResults = newsList.Count();
Then use the following to get previousItem and nextItem:
var previousItem = newsList.ElementAtOrDefault(currentIndexInNewsList - 1);
var nextItem = newsList.ElementAtOrDefault(currentIndexInNewsList + 1);
Instead of Children() you could also use SiblingsAndSelf() or Siblings() extension methods, but when getting previous or next node, you probably don't need the included the node itself, so it will probably work with both of these extension method.
In Umbraco v7 for Previous() extension method it returned the parent node, when the current node was first child.
So for a structure like the following and if current step was "Billing" I think Previous() extension method in v7 returned the "Basket" node.
Siblings() ? Umbraco 8
I think Umbraco 8 is missing the siblings / sibling method?
Anyone managed to find it / its replacement?
You could use .Parent().Children() as a temporary solution
I can’t seem to find the impl in either v7 or v8. Should be an Easy addition, if it was not removed on purpose
Hey, I thought the same, unfortunately the node i need is a sibling of the root node, so in this instance there is no .parent()
Hi Dave
I have created an issue for this https://github.com/umbraco/Umbraco-CMS/issues/4839
It seems many of these extension methods is not available in v8 and they are in v7.
/Bjarne
Thanks Bjarne, hopefully there'll be an update soon
Hello, I am having same issue. I am using Next() but it is not working on Umbraco 8. Has Next() been replaced by something else? Thanks, Kusum
Hi,
Did you resolve this? I'm also wanting to use .Next() in v8
Thanks
Kerri
Hi Kerri, k, Dave
V8.1 has seen the return of Siblings() and indeed SiblingsAndSelf()
Siblings will return the Siblings of the current item (but not the current item) and you guessed it SiblingsAndSelf() will include the current item too.
Next() and Previous() haven't been added back in however 'you could' create your own extension methods onto IPublishedContent to implement them, and now that we can easily get Siblings, it's quite straightforward. If you add something like the following to your projects:
and then if you add a using reference to this namespace:
Then you'll be able to use the basic form of Next() and Previous() in a similar way to V7:
There are lots of other V7 PublishedContentExtensions... and overloads of Next and Previous here:
https://github.com/umbraco/Umbraco-CMS/blob/v7/dev/src/Umbraco.Web/PublishedContentExtensions.cs
that could be implemented in the same way if you need them.
Maybe we could coordinate a central git repository of these helpers to build them up as required as people bridge existing V7 solutions to V8.
regards
Marc
Hi Kerri
There was another forum thread here about the missing
Previous()
andNext()
extension methods.Here is a simple example of how to solve this.
https://our.umbraco.com/forum/umbraco-8/97496-previous-next-plus-umvbraco-8#comment-308874
Then use the following to get previousItem and nextItem:
Instead of
Children()
you could also useSiblingsAndSelf()
orSiblings()
extension methods, but when getting previous or next node, you probably don't need the included the node itself, so it will probably work with both of these extension method.In Umbraco v7 for
Previous()
extension method it returned the parent node, when the current node was first child.So for a structure like the following and if current step was "Billing" I think
Previous()
extension method in v7 returned the "Basket" node.Basket
/Bjarne
Thanks for the replies Bjarne and Marc,
I ended up using Bjarne's solution.
is working on a reply...