Copied to clipboard

Flag this post as spam?

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


  • lucuma 261 posts 563 karma points
    Mar 06, 2011 @ 06:44
    lucuma
    0

    Ancestors(2) not returning all the Ancestors (4.7RC)

    I've got a setup like the following.  

    -root
    --about
    ----info
    ------moreinfo

    Ok, my breadcrumb looks like this:

    <ul>
      <li><a href="/?mobile=1">Home</a></li>
      @foreach(var level in @Model.Ancestors(2))
      {
        <li><a href="@level.Url?mobile=1">@level.Name</a></li>
      }
      <li>@Model.Name</li>       
    </ul>

    Ths is what gets returned:  Home | about | moreinfo

    Is there some reason that info is being skipped in my example?  I was assuming that the Ancestors would return all the parents.

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Mar 07, 2011 @ 16:30
    Sebastiaan Janssen
    1

    It's not actually being skipped, "2" is the index of your ancestor, so you're only getting ancestor number 2. Why not use ancestors without the number?

    Or, if you want to filter by level, do something like: 

    @Model.Ancestors().Where("Level > 2")
  • lucuma 261 posts 563 karma points
    Mar 07, 2011 @ 18:24
    lucuma
    0

    Thanks, that's exactly what I needed.

Please Sign in or register to post replies

Write your reply to:

Draft