Copied to clipboard

Flag this post as spam?

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


  • Ram Prahalad 11 posts 101 karma points
    Jul 20, 2022 @ 21:05
    Ram Prahalad
    0

    UmbracoHelper in Version 8.5?

    Hello All,

    I have about 200 run time errors just based on this UmbracoHelper. I have googled/forumed enough. But I just can't seem to find the correct equivalent of this below line(s).

    Any links to the documentation or solutions will be of great help. Thanks!

    var umbracoHelper = new Umbraco.Web.UmbracoHelper(Umbraco.Web.UmbracoContext.Current);
        var rootNodes = umbracoHelper.TypedContentAtRoot();
    
  • Nathan Woulfe 447 posts 1665 karma points MVP 5x hq c-trib
    Jul 20, 2022 @ 23:04
    Nathan Woulfe
    0

    Hi Ram, it depends on where you're accessing the helper, and what you're using it for, generally though I'd lean on DI and inject the helper:

    private readonly UmbracoHelper _helper;
    
    public MyClass(UmbracoHelper helper) => _helper = helper;
    

    That said though, there doesn't appear to be a TypedContentAtRoot method on the UmbracoHelper class in v8 (it did exist in v7)

    Given that, you could do something like this:

    IEnumerable<MyType> myTypedNodes = _helper.ContentAtRoot().OfType<MyType>();
    

    It is usually possible to get the same values from other places rather than using the UmbracoHelper - IPublishedContentQuery also exposes the ContentAtRoot method, and (I'm guessing) would be a lighter dependency

  • Ram Prahalad 11 posts 101 karma points
    Jul 21, 2022 @ 12:52
    Ram Prahalad
    0

    Hi @Nathan,

    Thanks a lot for your response! For now, this code is in a dll.

    I shall try it out.

    Appreciate your help!

  • 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