Copied to clipboard

Flag this post as spam?

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


  • Adam Jenkin 71 posts 226 karma points
    Feb 17, 2011 @ 15:51
    Adam Jenkin
    0

    Fetching homepage Node from NodeFactory

    I would like to use the node factory to fetch a node representing the home page.

    As the NodeID is not constant (I think). The only way I can see how todo this is with the following

    Node.GetNodeByXpath("/");

    However, this returns a null node.

    Whe on the homepage, both the following work to access the node:

    Node.GetCurrent();
    Node homepage = new Node(1050);

    However, I dont want to use either of these approaches.

    Many Thanks,

    Adam

  • Gerty Engrie 130 posts 489 karma points c-trib
    Feb 17, 2011 @ 16:11
    Gerty Engrie
    3

    You can use: GetNodeByXPath("//*[@id=" + Node.GetCurrent().Id + "]/ancestor-or-self::doctypealiasoftheroot")

    hope it helps :)

    Gerty

  • Adam Jenkin 71 posts 226 karma points
    Feb 17, 2011 @ 16:58
    Adam Jenkin
    0

    Thanks Gerty, 

    That kind'a works :/ I seem to get a paritially filled node object with that query. Here is a copy of the watch in VS

    Any ideas?

  • Adam Jenkin 71 posts 226 karma points
    Feb 18, 2011 @ 10:24
    Adam Jenkin
    0

    Should the above xpath expression return a fully populated node object for the homepage?

  • Gerty Engrie 130 posts 489 karma points c-trib
    Feb 18, 2011 @ 12:20
    Gerty Engrie
    0

    No idea, i usually use umbraco.library.GetXmlNodeByXPath :)

  • Adam Jenkin 71 posts 226 karma points
    Feb 18, 2011 @ 13:32
    Adam Jenkin
    0

    Thanks Gerty, umbraco.library.GetXmlNodeByXPath works for me :)

  • Jonas Eriksson 930 posts 1825 karma points
    Feb 18, 2011 @ 14:36
    Jonas Eriksson
    1

    I was just thinking (and tweeting) 'bout the best way to store site wide settings (once again), web.config or site root node. The latter seems to be the de facto standard.

    For multi-site installations I use this uQuery-to get the site root node (level 2):

    var siteRootNode = uQuery.GetCurrentNode().GetAncestorOrSelfNodes().FirstOrDefault(node => node.GetDepth()==2);

    And to get a setting (integer):

    var searchPageNodeId = siteRootNode.GetPropertyAsInt();

     

  • Jacob 41 posts 90 karma points
    Apr 07, 2014 @ 20:01
    Jacob
    0

    ++ to Gerty for the practical solution.

     

    I ended up using GetNodeByXPath("//*[@id=" + 1337 + "])  where 1337 is the node id of the master node I'd like to reference.  In my environments I find myself referencing the content of a single node from various locations throughout the site, so the use of a 'master' node for holding configurable content in a single place proved highly resourceful.

Please Sign in or register to post replies

Write your reply to:

Draft