Copied to clipboard

Flag this post as spam?

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


  • Kyle Skrinak 272 posts 327 karma points
    Aug 14, 2012 @ 16:00
    Kyle Skrinak
    0

    Running a conditional check for current node descendantsorself

    I'd like to do something like

        if (model.id(1066).descendantsorself() == true) { do stuff }

    That, I presume, merely generates a list.I only want to execute the block if the node matches that criteria.

    How to run such a check?

    Thanks,

    Kyle

  • Kyle Skrinak 272 posts 327 karma points
    Aug 14, 2012 @ 17:19
    Kyle Skrinak
    0

    This almost looks right, but its not working:

    if (Model.IsDescendantOrSelf(1066)) { do something }

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Aug 14, 2012 @ 18:02
    Hendy Racher
    0

    Hi Kyle,

    Just a thought it might be more efficient to do the reverse, ie, check to see if the current page is an ancestor of 1066 ?

  • Kyle Skrinak 272 posts 327 karma points
    Aug 14, 2012 @ 19:48
    Kyle Skrinak
    1

    Dang, Hendy, I was hoping that was it: (Model.IsAncestorOrSelf(1066)) or @(Model.IsAncestorOrSelf(1066)) render the same 'nothingness


    Once again, my umbraco partner in crime crafted an answer:

    @using umbraco.MacroEngines;

      var targetId = 1202;
      DynamicNodeList ancestors = Model.AncestorsOrSelf();

    if (@ancestors.Items.Any(x=>x.Id==targetId)) {do stuff}
Please Sign in or register to post replies

Write your reply to:

Draft