Copied to clipboard

Flag this post as spam?

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


  • Amigo 245 posts 600 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 245 posts 600 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);
        }
    
  • 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