Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Damian Green 452 posts 1433 karma points
    Jun 12, 2014 @ 16:41
    Damian Green
    0

    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:

      @{
        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 ===-->
    
  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jun 16, 2014 @ 11:14
    Jeavon Leopold
    2

    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

  • Damian Green 452 posts 1433 karma points
    Jun 16, 2014 @ 12:35
    Damian Green
    0

    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

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x admin c-trib
    Jun 16, 2014 @ 13:43
    Jeavon Leopold
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft