Global Context
Global contexts in Umbraco provide a clean, type-safe way to share functionality across the backoffice.
The Global Context extension type allows developers to create a custom context of data and functions and make it available across the entire backoffice. Unlike other contexts that might be scoped to a specific workspace or view, global contexts are available everywhere for the duration of the backoffice session. Consider using a global context when you need to:
Share state across multiple extensions – for example, tracking user preferences or application-wide settings.
Manage centralized services – such as API clients, notification handlers, or data repositories.
Coordinate between different extensions – for instance, acting as a communication layer between dashboards and other components.
Share functionality with other extensions – allowing other package developers to access features and functionality within your package.
Provide a fallback context – serving as the fallback context when no other contexts match the consumer’s scope.
Prefer other context types such as Workspace Contexts over Global Contexts. Umbraco itself uses Global Contexts sparingly, for example, for clipboard data, the current user, and icons.
Registration of a Global Context
Global Context extensions are registered using a umbraco-package.json manifest file.
Key fields:
type: Must be"globalContext", see: ManifestGlobalContextalias: A unique identifier for the contextname: A human-readable nameapi: The path to the compiled JavaScript file
{
"$schema": "../../umbraco-package-schema.json",
"name": "My Global Context Package",
"version": "1.0.0",
"extensions": [
{
"type": "globalContext",
"alias": "My.GlobalContext",
"name": "My Global Context",
"api": "/App_Plugins/my-global-context/dist/my-context.context.js"
}
]
}Creating Your Global Context
1. Define a Context Token
First, create a context token. This is how other parts of your extension will reference the context.
%}
%}
2. Implement the Context Class
Next, implement the context class.
Using Global Contexts
Once the global context extension is registered, it can be consumed in any web component throughout the backoffice.
Last updated
Was this helpful?