Copied to clipboard

Flag this post as spam?

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


  • Doogie Talons 183 posts 318 karma points
    Jun 05, 2019 @ 10:14
    Doogie Talons
    0

    Getting an Item from site route on any page

    Hi I am using umbraco 8, on some sub pages I want to call an item from the home page call it phoneNumber.

    I know I can use the fall back

    @Model.Value("phoneNumber", fallback:GallbackToAncestors)
    

    But is there any way to just call it directly from the page it is on rather than the fallback.

    Cheers

  • Matt Barlow | jacker.io 164 posts 740 karma points c-trib
    Jun 05, 2019 @ 12:20
    Matt Barlow | jacker.io
    100

    You can access that node directly from the umbraco helper, assuming that the homenode is at the root:

     var homenode = Umbraco.ContentAtRoot().FirstOrDefault();
     var telephone = homenode.Value("telephone");
    

    or if, it's a child of the root node:

    var rootNode = Umbraco.ContentAtRoot().FirstOrDefault();
    var homeNode = rootNode.Children().Where(x => x.ContentType.Alias == "homeNodeContentAlias").FirstOrDefault();
    var telephone = homeNode.Value("telephone");
    

    Replace "homeNodeContentAlias" with the node content alias.

    or relative, from current node:

    var homeNode = Model.AncestorOrSelf(1);
    var telephone = homeNode.Value("telephone")
    
  • Doogie Talons 183 posts 318 karma points
    Jun 05, 2019 @ 12:35
    Doogie Talons
    0

    Excellent the top one worked a treat in this instance, the others will prove useful in future, thanks for your response.

Please Sign in or register to post replies

Write your reply to:

Draft