Copied to clipboard

Flag this post as spam?

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


  • Paul Marden 235 posts 338 karma points MVP 2x c-trib
    May 19, 2012 @ 13:39
    Paul Marden
    0

    Problem with .AncestorsOrSelf(Level) and (doctype) in upgraded site

    I've got some issues with a razor script I've written.

    foreach (var page in @Model.AncestorsOrSelf(3))
     {
        <p>@page.NodeTypeAlias</p>
      }

    It seems to output pages that aren't at level 3.  Is that me misunderstanding the .AncestorsOrSelf(level) or is it a problem with my site.

    I also can't get to grips with .AncestorsOfSelf(doctypealias)

    foreach (var page in @Model.AncestorsOrSelf("CountryHomepage"))
     {
        <p>@page.NodeTypeAlias</p>
      }

    Is returning:

    KnowledgeBaseChannel

    How does that work!   This is an umbraco instance that I've upgraded from 4.0.something to 4.7.2 this week and I'm transitioning the old xslt to razor.  I need to get this live by end of Monday, please help.

  • Jeroen Breuer 4908 posts 12265 karma points MVP 5x admin c-trib
    May 19, 2012 @ 19:22
    Jeroen Breuer
    0

    Razor doesn't work with the legacy xml so if you're still using that you need to change it to the new xml format.

    Jeroen

  • Jonas Eriksson 930 posts 1825 karma points
    May 19, 2012 @ 20:23
    Jonas Eriksson
    1

    Hi, I think you just need to remove that "s", AncestorOrSelf(3), see also http://umbraco.com/follow-us/blog-archive/2011/3/13/umbraco-razor-feature-walkthrough-part-5.aspx

    @Model.AncestorsOrSelf("CountryHomepage") I dont think there's an overload for that, perhaps Model.AncestorsOrSelf.CountryHomepage works (but I would use the index if possible).

     

  • Paul Marden 235 posts 338 karma points MVP 2x c-trib
    May 20, 2012 @ 10:59
    Paul Marden
    0

    @Jeroen - Thanks I'd already thought about that, and set to new XML schema & republished

    @Jonas - using AncestorOrSelf(3) works.  But I don't understand the meaning of AncestorsOrSelf.  

  • Jonas Eriksson 930 posts 1825 karma points
    May 20, 2012 @ 12:01
    Jonas Eriksson
    0

    Good to hear it works. :)

    The meaning of AncestorsOrSelf is to return all ancestors + self. The integer overload I never tried: "A level filtered call .Method(int) - returns nodes which are <= or >= (depending on if you're using Ancestors or Descendants) the desired number" (see the link).

    I use razor with legacy xlst schema on a few sites, cannot see why it should be a problem? 

Please Sign in or register to post replies

Write your reply to:

Draft