Context API | Umbraco CMS
# package-development
i
Hello , I want to consume UMBBLOCKENTRY_CONTEXT inside of a UmbUfmComponentBase. how to use UmbContextConsumer this page does not give much details https://docs.umbraco.com/umbraco-cms/customizing/foundation/working-with-data/context-api#alternative-solutions any help would be much appreciated thanks
l
Hi @ICanCSharp, Unfortunately, the
UmbUfmComponentBase
base class doesn't have access to the
consumeContext()
method, as it's used to make the mapping between the UFM syntax and a web component, (
UmbUfmComponentBase
is not a web component in itself). The way to do this would be to create a class that extends the
UmbUfmElementBase
base class, as that does have access to Umbraco's context API. For an example, see how it's done for the built-in `UmbUfmLabelValueElement`: https://github.com/umbraco/Umbraco.CMS.Backoffice/blob/v14.3.0-rc/src/packages/ufm/components/label-value/label-value.element.ts As for a code snippet, here's something that may help. First import the Block context.
Copy code
import { UMB_BLOCK_ENTRY_CONTEXT } from '@umbraco-cms/backoffice/block';
Then in the constructor, consume the Block context.
Copy code
constructor() {
    super();

    this.consumeContext(UMB_BLOCK_ENTRY_CONTEXT, (context) => {
        this.observe(
            context.content,
            (content) => {
                console.log('UMB_BLOCK_ENTRY_CONTEXT.content', content);
            },
            '_observeBlockContent',
        );
    });
}
Hope this helps.
i
Thank you very much i will check it asap
it worked perfectly !! Awesome
thanks
Hello @leekelleher ! thanks to your help earlier i managed to create a pull request making this (decide the label of a grid dynamically) a general feature in Umbraco, and they have put you a reviwer. Kindly review my Pr and tell me if there is anything i can help you with https://github.com/umbraco/Umbraco.CMS.Backoffice/pull/2345
25 Views