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 129 posts 436 karma points
    30 days ago
    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 372 posts 1576 karma points
    30 days ago
    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 1299 posts 5501 karma points MVP 3x c-trib
    30 days ago
    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 129 posts 436 karma points
    17 days ago
    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