Copied to clipboard

Flag this post as spam?

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


  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 16, 2013 @ 14:15
    Fuji Kusaka
    0

    IsLast() not working

    Hi Guys,

    I have a weird issue here where IsLast() is not working in a loop after making some if statements.

    Under my content section i have a folder node under which admin can add multiple nodes each with a specific property Check box. They all have different templates that is 4 different ones depending on the property attributed.

    I need to displayable a line under the last content but doesnt seems to be working though

     

      @foreach(var p in projects.Children){
                       if (p.Where("cibPar") && p.Where("cibNonMau") && p.Where("cibLoc")){
                              if(p.typeOfProduct == "test" || p.typeOfProduct == "test,test2"){       
                                <li class="@Library.If((!p.IsLast()), "last clearfix","clearfix")">
                                    </li>
                              }
                          }                  
                        }

     

    Looks like its taking the last node in the folder instead. Not the last node with the same property . 

    Any suggestion what i might be doing wrong here ?

     

  • Mike Chambers 635 posts 1252 karma points c-trib
    Jan 16, 2013 @ 14:18
    Mike Chambers
    0

    We had problems with Last, first etc.. and ended up adding in a counter and comparing against 0 or Children.Count

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 16, 2013 @ 14:20
    Fuji Kusaka
    0

    But here dont know the exact number of nodes the client will be adding. So count will not be a good solution to me

  • Mike Chambers 635 posts 1252 karma points c-trib
    Jan 16, 2013 @ 14:22
    Mike Chambers
    0

    not sure what you mean projects.Children.Count will give the number of nodes added to your projects node???

  • Fuji Kusaka 2203 posts 4220 karma points
    Jan 16, 2013 @ 14:24
    Fuji Kusaka
    0
    var projects = Model.NodeById("1111"); 

    Here all the templates will be pulling nodes from content folder with id 1111

  • Mike Chambers 635 posts 1252 karma points c-trib
    Jan 16, 2013 @ 14:36
    Mike Chambers
    0

    sorry @Fuji you've lost me...

    IsLast() if it was working would give you the last node from projects.Children (eg the last node of your enumeration)

    are you wanting the last node from projects.Children filtered as per your ifs?

     

    if so then you need to filter at the enurmeration level... so that your foreach only enumerates through your filtered set...

    DynamicNode projects = Library.NodeById("1111");
        foreach (var item in projects.Children.Where(x => x.NodeTypeAlias == "SomeTemplate"))
        {
    
        }

     

    As you have it you have no way of knowing that the last child of projects will necessarily satisfy your if statements???

    Or I could be completely misunderstanding you???

  • Niels Jorck Ellegaard 39 posts 245 karma points
    Jan 22, 2013 @ 11:55
    Niels Jorck Ellegaard
    0

    I made a long post, before our.umbraco.org died...

    Oh well I'll try again.

    With your .IsLast() you are asking if p is the last item in your collection, and it isnt.

    You have more items in your collection, that simply doesn't fit your if statements.

    What you want to do is trim down your collection so you only have the items in it, that you want to show.

    This isn't 100% accurate, but it should give you an idea of what I mean.

    @foreach(var p in projects.Children.Where(p => p.Where("cibPar") && p.Where("cibNonMau") && p.Where("cibLoc")).Where(p => p.typeOfProduct == "test" || p.typeOfProduct == "test,test2"))
      {
      <li class="@Library.If((!p.IsLast()), "last clearfix","clearfix")">
    </li>
      } 
    I hope it will be of help :)
Please Sign in or register to post replies

Write your reply to:

Draft