Layout Context
When creating widget layouts in the Widget Builder, you have access to various data objects and properties through Handlebars expressions. This guide explains what data is available and how to use it in your layout.
Available Context Objects
The following objects and properties are available in your widget layout:
settings
Contains the configuration values for your widget that were set by the editor when adding the widget to a page.
Usage:
Example:
If you define a text field called "title" in your Widget Settings, it will be accessible as {{settings.title}}.
data
Contains the response data from your API request (if configured). This is the main data source for most dynamic widgets.
Usage:
page
Contains information about the current Staffbase page where the widget is displayed.
Available properties:
- Various page-related properties from the Staffbase Web Extensions (see Staffbase documentation)
Usage:
user
Contains information about the current user viewing the widget.
Available properties:
- User profile information from Staffbase
- Properties depend on the Staffbase user object structure
Usage:
widget
Contains metadata about the widget itself and contextual information.
Available properties:
| Property | Type | Description |
|---|---|---|
widget.baseId | string | Unique base identifier for the widget instance |
widget.className | string | Generated CSS class name for styling isolation |
widget.title | string | The widget's title |
widget.updated | string | Last update timestamp of the widget |
widget.contentLanguage | string | The content language for the widget (see Language Support) |
Usage:
variables
Contains custom variables that you define in the Widget Builder. These can be used to store state or dynamic values that change during user interaction.
Usage:
You can update variables using JavaScript functions like setVariable() in your template.
defaultLocale
Contains the default locale from Staffbase's contentLanguage setting (e.g., "en_US", "de_DE").
Usage:
browserLanguage
Contains the browser's language from navigator.language (e.g., "en", "de").
Usage:
browserTimezone
Contains the browser's timezone detected via the Intl API (e.g., "Europe/Berlin", "America/New_York").
Usage:
Language Support
The Widget Builder automatically detects and provides the content language through widget.contentLanguage. This value follows a priority chain:
- contentLanguage from Staffbase SDK -
Usage example:
Using with datetime helper:
This will format dates according to the user's language preference.
Timezone Support
The Widget Builder provides timezone information through browserTimezone. The timezone is automatically detected from the user's browser via the Intl API (e.g., "Europe/Berlin", "America/New_York"). If detection fails, it falls back to "Europe/Berlin".
Usage example:
Using with datetime helper:
This will display times in the user's local timezone.
Combining Language and Timezone
You can combine language and timezone for truly localized experiences:
This will display the date and time in the user's language and timezone.
Example: Localized Greeting
Here's a complete example showing how to use language and timezone together:
Best Practices
- Always provide fallbacks: Use conditional helpers to provide content in multiple languages or default values
- Test with different locales: Preview your widget with different language and timezone settings
- Use semantic formatting: Leverage the
datetimehelper's locale-aware formatting instead of hardcoding date formats - Consider user preferences: The automatic language/timezone detection respects user settings, so design widgets that adapt gracefully
Related Documentation
- Handlebars Helpers - Learn about all available helpers
- DateTime Helper - Detailed documentation on date/time formatting with locale and timezone support
- Customize a Built-in Widget - See context objects in action