Copied to clipboard

Flag this post as spam?

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


  • Hardy Wang 91 posts 112 karma points
    Jul 11, 2011 @ 17:20
    Hardy Wang
    0

    How to get current page inside the node tree

    Hi all,

    I have found quite some very cool implementations how to use Razor to create navigation. My understanding is that I need to use @Model.AncestorOrSelf() or var items = node.Children.Where("Visible").Where("Level <= maxLevelForSitemap", values); to obtain list of nodes at each level. The sample I used is http://our.umbraco.org/forum/developers/razor/21519-Razor-code-for-complete-navigation

    I usually have this razor script in my template (master) page to be used by all content pages.

    But my question is that how can I get current page from the node tree? For example I need to have some special effects (e.g. bolder text or different background color) on current selected page's navigation item inside a tree. I checked umbraco.MacroEngine.dll and I could not find a property or function to get Self.All I see is AncestorOrSelf() or DescendantsOrSelf(), do I have to find overlapped items from these 2 lists to get Self?

    Thanks

    Hardy

  • Sebastiaan Janssen 5058 posts 15520 karma points MVP admin hq
    Jul 11, 2011 @ 17:23
    Sebastiaan Janssen
    0

    How about:

    if(node.Id == Model.Id) {
    <strong>This is the current node..</strong>
  • Hardy Wang 91 posts 112 karma points
    Jul 12, 2011 @ 03:46
    Hardy Wang
    0

    Great, thanks!

Please Sign in or register to post replies

Write your reply to:

Draft