Copied to clipboard

Flag this post as spam?

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


  • lori ryan 239 posts 573 karma points
    Jun 13, 2020 @ 12:44
    lori ryan
    0

    Multiple Root nodes - get property

    I have multiple root nodes - just wondering was the best way to navigate to say the b node and grab x property?

    Have been using the below - but worried about performance.

        var root = Model.AncestorOrSelf(1);
        var settings = root.Siblings().FirstOrDefault(x => x.ContentType.Alias == "MyNodeAlias");
    
      var property= settings.Value("MyProperty");
    
  • Bo Jacobsen 597 posts 2395 karma points
    Jun 13, 2020 @ 17:42
    Bo Jacobsen
    0

    You could try this and compare performance.

    var settings = Umbraco.ContentAtRoot().FirstOrDefault(x => x.ContentType.Alias == "MyNodeAlias");
    var property = settings.Value("MyProperty");
    
  • Nik 1593 posts 7151 karma points MVP 6x c-trib
    Jun 13, 2020 @ 19:36
    Nik
    100

    Another option you have, is have a picker on your home node that allows you to pick the settings node.

    Then you can do Model.Root().Value<IPublishedContent>("settings") to get the setting node.

    All of the suggested options can work, and in reality there isn't much of a performance issue in using Siblings approach as everything is in memory anyway.

    Thanks

    Nik

  • lori ryan 239 posts 573 karma points
    Jun 26, 2020 @ 14:26
    lori ryan
    0

    Any benefit using something like

       var settings = Umbraco.ContentSingleAtXPath("//MyNodeAlias");
    
Please Sign in or register to post replies

Write your reply to:

Draft