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 199 posts 529 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 438 posts 1818 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 1413 posts 6212 karma points MVP 3x 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 199 posts 529 karma points
    Jun 26, 2020 @ 14:26
    lori ryan
    0

    Any benefit using something like

       var settings = Umbraco.ContentSingleAtXPath("//MyNodeAlias");
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies