Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
I have a collection of nodes that were built by passing in an array to the Umbraco.TypedContent([]) helper.
There are 2 items in the collection (it is for a breadcrumb and was build from the Path variable on the current page).
So in the collection i have (in this order) Home Sub Page
When i iterate over the collection with a foreach - the Home node returnd true to is last and the SubPage returns false.
Confused as to why that would be?
Any ideas?
I have changed he way i check for this now but would like to know why this wouldn't work as it was supposed to.
cheers Damian
Heres the code:
@{ var pathNodes = Umbraco.TypedContent(Model.Content.Path.Replace("-1", "").Split(new string[] {","}, StringSplitOptions.RemoveEmptyEntries)); } <!--=== Breadcrumbs ===--> <div class="breadcrumbs"> <div class="container"> <h1 class="pull-left">@Umbraco.Field(Model.Content, "displayName", altFieldAlias: "pageName")</h1> <ul class="pull-right breadcrumb"> @foreach (var node in pathNodes) { if (node.IsLast()) { <li class="active">@Umbraco.Field(node, "displayName", altFieldAlias: "pageName")</li> } else { <li><a href="@node.Url">@Umbraco.Field(node, "displayName", altFieldAlias: "pageName")</a></li> } } </ul> </div> </div><!--/breadcrumbs--> <!--=== End Breadcrumbs ===-->
Hi Damian,
I'm going to take a guess you are either using v6.2 or v7.1? There was a change in these versions, you need to add the ToContentSet() to the collection.
This should fix it:
@foreach (var node in pathNodes.ToContentSet())
More details on the change here
Jeavon
Hi Jeavon,
I am using 7.1.3 where i hd the issue.
Will give it another try. Is the ToContentSet() just a workaround or is that the new way to work with collections if you want to use the IsX items?
Thanks Damian
It is the way to do it now. Without it, the "IsSomething" helpers now relate to the items position with it's siblings in the tree.
Let me know if it fixes it for you.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
IsLast() returning true for the first item in the list rather than the last!?
I have a collection of nodes that were built by passing in an array to the Umbraco.TypedContent([]) helper.
There are 2 items in the collection (it is for a breadcrumb and was build from the Path variable on the current page).
So in the collection i have (in this order) Home Sub Page
When i iterate over the collection with a foreach - the Home node returnd true to is last and the SubPage returns false.
Confused as to why that would be?
Any ideas?
I have changed he way i check for this now but would like to know why this wouldn't work as it was supposed to.
cheers Damian
Heres the code:
Hi Damian,
I'm going to take a guess you are either using v6.2 or v7.1? There was a change in these versions, you need to add the ToContentSet() to the collection.
This should fix it:
More details on the change here
Jeavon
Hi Jeavon,
I am using 7.1.3 where i hd the issue.
Will give it another try. Is the ToContentSet() just a workaround or is that the new way to work with collections if you want to use the IsX items?
Thanks Damian
Hi Damian,
It is the way to do it now. Without it, the "IsSomething" helpers now relate to the items position with it's siblings in the tree.
Let me know if it fixes it for you.
Jeavon
is working on a reply...