Copied to clipboard

Flag this post as spam?

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


  • Marcos 9 posts 30 karma points
    Apr 11, 2012 @ 11:35
    Marcos
    0

    Umbraco 5.1: get ancestor at certain level

    Hi everybody. I'm new here. I discover Umbraco since a couple of months and found it great. I already created some cool websites with v4. So I just started playing with v5.

    Here goes my problem. I have a multilanguage site with a structure like this:
    root
    ---- subdomain.domain.com
    --------- en
    --------- it
    --------- sp
    --- subdomain2.domain.com
    --------- en
    --------- it
    --------- sp

    Now my menus and stuff have all a parameter that is level (almost always equal to 2). With v4 I used to get each language directory leve (it, en and so on) with

    @DynamicModel.AncestorOrSelf(level) 
    It was great. Everything was ok. But now with v5 AncestorsOrSelf has no paramters (aaaagh!!!).

    I tried with

    @DynamicModel.AncestorsOrSelf.Last().Children.Where("Level==@0",2).First()

    But I had no luck because it seems there's a issue on it (http://issues.umbraco.org/issue/U5-359)

    Any ideas?

    Thanks

    Marcos

  • Grant Thomas 291 posts 324 karma points
    Apr 11, 2012 @ 15:39
    Grant Thomas
    0

    You could try a couple of things here. First try comparing the properties as strings proper, and also casing might come into play:

    @DynamicMode.AncestorsOrSelf.Last().Children.Where("level == @0", "2").First()
  • Marcos 9 posts 30 karma points
    Apr 11, 2012 @ 17:38
    Marcos
    0

    Nope. The only solution I've found is a workaround. But it's not ideal:

     

          @foreach(var node in DynamicModel.AncestorsOrSelf){
                if(node.Level==2){
                <li><a href="@node.NiceUrl">@node.pageTitle</a></li>
                    foreach(var subnode in node.Children.Where("UmbracoNaviHide != @0", "True")){
                 <li><a href="@subnode.NiceUrl">@subnode.pageTitle</a></li>
                    }
                }
              }

    I think I'm going back to v4. Too many bugs and issues

     

Please Sign in or register to post replies

Write your reply to:

Draft