Copied to clipboard

Flag this post as spam?

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


  • Amigo 243 posts 568 karma points
    Sep 30, 2023 @ 21:32
    Amigo
    0

    UmbracoHelper in Custom field

    Hi Im trying to inject UmbracoHelper in my custom field. But i get this error:

    Cannot consume scoped service 'Umbraco.Cms.Web.Common.UmbracoHelper' from singleton 'xxx.Forms.MyCustomField'.)

    I did follow this: https://docs.umbraco.com/umbraco-forms/developer/extending/adding-a-fieldtype

    Why can't I do that? I need loop some published content. to check if some content id's exist.

  • Amigo 243 posts 568 karma points
    Sep 30, 2023 @ 22:25
    Amigo
    100

    I ended up doing this instead:

    var accessor = StaticServiceProvider.Instance.GetRequiredService<IUmbracoHelperAccessor>();
    
        if (accessor.TryGetUmbracoHelper(out var umbracoHelper))
        {
            var contentnode= umbracoHelper.Content(1234);
        }
    
Please Sign in or register to post replies

Write your reply to:

Draft