daun / statamic-multisite-field
Fieldtype for storing localized values in non-localizable contexts
Package info
github.com/daun/statamic-multisite-field
Language:JavaScript
Type:statamic-addon
pkg:composer/daun/statamic-multisite-field
Requires
- php: ^8.2
- statamic/cms: ^6.35.1
Requires (Dev)
- larastan/larastan: ^2.9 || ^3.0
- laravel/pint: ^1.14
- mockery/mockery: ^1.6
- orchestra/testbench: ^9.5 || ^10.0
- pestphp/pest: ^3.3
- pestphp/pest-plugin-laravel: ^3.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Fieldtype for entering localized values in places Statamic doesn't usually localize — asset blueprints, form configs, globals without localization, and other "site-less" contexts.
It wraps a single field of any type, stores one value per site, and augments to the current site's value on the frontend.
Installation
composer require daun/statamic-multisite-field
Usage
Add a multisite field to a blueprint and configure the field it wraps. Define display
and instructions on the root multisite field, not the wrapped field.
caption: type: multisite display: 'Caption' instructions: 'Shown below the image' field: type: text
Frontend Display
Values are augmented to the current site's value on the frontend. Use like any other field.
{{ caption }}
Storage
Values are stored keyed by site handle.
caption: en: 'Welcome home' fr: 'Bienvenue chez vous'
Existing fields
Upgrading an existing field (e.g. text or url) to multisite just works:
previously stored values are treated as the default site's value and
upgraded to the per-site format on the next save.
Field Configuration
| Option | Default | Description |
|---|---|---|
field |
— | The wrapped field's configuration (required). |
layout |
default |
How to display the sites: one at a time behind a switcher (tabs, bottom, start, end, action, actions) or all at once (stack). default uses the configured default, tabs unless changed. |
inherit |
true |
Fall back to the default site's value when a site has no own value. |
fallback |
— | Handle of a sibling field in the same publish context to fall back to when the default site has no value. |
Site Switcher Layout
In the control panel, the field shows the input for a single site at a time. Switch sites with the tabs above the field. All multisite fields on a page switch together, so you always see one consistent site across the form.
The layout field config controls how to switch sites.
Tabs
The default value of tabs shows a tab bar above the field.
Button Groups
The values bottom, start or end show a button group next to the field.
Field Actions
The value action adds one action to the field header that shows the current site's short label (e.g. EN) and cycles through authorized sites. The value actions adds one quick action per site, showing its short label; the selected site is highlighted. Full site labels appear in the action tooltips. See Site Labels to change both.
Actions provided by the wrapped field (including custom actions) appear in the same header, with the current site's value and meta. In the stacked layout, wrapped-field actions are prefixed with their site names. The field's Show Actions setting controls whether the header actions are displayed.
Stacked
The value stack shows all sites in a single column, without a switcher.
Inheritance
A multisite field can inherit from a sibling in the same blueprint, in addition to inheriting between its own sites. This is useful for adding optional per-site translations of a field that already has a default value.
display: type: text display_i18n: type: multisite inherit: true fallback: display field: type: text
Global Site Switcher
With many multisite fields on one form, the per-field switchers add up. Add a
multisite_switcher field to the blueprint to show a single global switcher
that controls all multisite fields. Any multisite fields on the same form will
then hide their own switchers.
Choose between three layouts: tabs, buttons or dropdown. Leave it on default to use
the configured default, tabs unless changed.
site_switcher: type: multisite_switcher layout: tabs
The switcher is a display-only field — it stores no data.
Configuration
Publish the config file to change the defaults for all fields:
php artisan vendor:publish --tag=statamic-multisite-field-config
It lets you change:
- the site label shown in tabs, buttons, dropdowns, headings and tooltips (
label) - the short site label shown in the compact field actions (
label_short) - the default layout of multisite fields (
layout) - the default layout of global switchers (
switcher_layout)
Default Layouts
Multisite fields and global switchers default to the default layout, which resolves to
layout and switcher_layout from the config file. Change those to restyle every field at
once; fields with an explicit layout keep it.
Site Labels
Sites are labelled by their name in tabs, buttons, dropdowns and stack headings, and by
their uppercase language (EN, DE) in the compact field actions. When several sites
share a language, the short label uses the locale's region instead (DE, CH).
label and label_short accept name, handle, lang, locale or any custom site
attribute as attributes.{key}. Short labels derived from the handle, language or locale
are uppercased; names and attributes are used as written. Sites without a value fall back
to the defaults.
# resources/sites.yaml de: name: Deutsch locale: de_DE url: /de/ attributes: flag: 🇩🇪
Limitations
- Listings and previews use the default site's value.
- Field conditions targeting the wrapped field are not supported.