Copied to clipboard

Flag this post as spam?

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


  • Rob Watkins 369 posts 701 karma points
    Jul 20, 2012 @ 11:41
    Rob Watkins
    0

    HasAccess() on lists

    Is there any way of doing something like n.Children.Where("Visible").HasAccess() to get a list of visible available nodes? I can do it with an if condition inside the foreach of course, but is there a nicer way?

  • Fuji Kusaka 2203 posts 4220 karma points
    Jul 20, 2012 @ 12:18
    Fuji Kusaka
    0

    Hi Rob,

    Are you doing something like

    if(!n.umbracoNaviHide){
      //do something
    }

    //fuji

  • Rob Watkins 369 posts 701 karma points
    Jul 20, 2012 @ 12:47
    Rob Watkins
    0
    @foreach(var n in Model.AncestorOrSelf().Children.Where("Visible"))    {
    if(n.HasAccess) {       
    // Show node
    }
  • Sören Deger 733 posts 2844 karma points c-trib
    Jul 20, 2012 @ 13:19
    Sören Deger
    0

    Hi Rob, you can use this, too:

    @foreach(var n inModel.AncestorOrSelf().Children.Where("Visible"))     {
    if(library.HasAccess(n.Id, n.Path)) {
    // Show node
    }
    }


  • Douglas Ludlow 210 posts 366 karma points
    Jul 20, 2012 @ 16:43
    Douglas Ludlow
    1

    @Rob, here's what you're looking for:

    dynamic nodes = Model.AncestorOrSelf().Children.Where("Visible && HasAccess");

    <ul>
    @foreach (var node in nodes)
    {
    <li><a href="@node.Url">@node.Name</a></li>
    }
    </ul>

    The Where method is really powerful, just be careful when dealing with a large amount of nodes as there have been some reported performance issues.

  • Rob Watkins 369 posts 701 karma points
    Jul 20, 2012 @ 16:46
    Rob Watkins
    0

    Ah! That's exactly it, I completely forgot about expressions in Where(), thanks Douglas. As it turns out the client has now added lots of other checks that make it ugly anyway, but I'll remember this for the future :o)

  • Douglas Ludlow 210 posts 366 karma points
    Jul 20, 2012 @ 17:03
    Douglas Ludlow
    0

    No problem. Glad I could help.

Please Sign in or register to post replies

Write your reply to:

Draft