Skip to main content

Schemas, assets and metadata

Besides the template, a widget definition describes what users can configure (options_schema), the shape of the data it renders (data_schema), and metadata such as aspect ratio, icons, bundled assets and translations. Castmill validates both schemas when you upload the widget.

Options schema​

options_schema maps each option key to a field definition. The dashboard renders a form from it when a user adds the widget to a playlist, and the template reads the values with options.<key> bindings.

{
"options_schema": {
"title": {
"type": "string",
"required": true,
"default": "Today's specials",
"order": 1
},
"accent": { "type": "color", "default": "#e8b04b", "order": 2 },
"duration": {
"type": "number",
"default": 20,
"min": 5,
"max": 300,
"description": "Seconds on screen",
"order": 3
},
"show_prices": { "type": "boolean", "default": true, "order": 4 },
"logo": { "type": "ref", "collection": "medias|type:image", "order": 5 }
}
}

For a field with no attributes, you can use the shorthand form: "subtitle": "string" is equivalent to "subtitle": { "type": "string" }.

Field types​

TypeDashboard controlValue in options
stringText input (or a select when enum is set)String
numberNumber input, bounded by min/maxNumber
booleanToggletrue or false
urlURL inputString
colorColor pickerCSS color string
locationMap location pickerObject with lat, lng, and optionally address, city, country, postalCode
refResource picker for the collection in collectionThe selected resource; see References
mapNested form built from schemaObject
listRepeatable entries built from itemsArray
layoutZone editorObject with aspectRatio and zones
layout-refLayout pickerReference to a saved layout

The layout and layout-ref types are used by the built-in Layout widget. See Layouts for the end-user side.

Field attributes​

AttributeApplies toDescription
typeAllField type from the table above. Required.
requiredAllThe form cannot be saved without a value.
defaultAllInitial value in the form.
descriptionAllHelp text shown with the field.
helpAllAdditional help text.
placeholderText fieldsPlaceholder shown when the field is empty.
min, maxnumberLower and upper bounds.
orderAllPosition of the field in the form, ascending.
enumstringAllowed values, rendered as a select.
collectionrefCollection to pick from. Required for ref.
schemamapField definitions of the nested object. Required for map.
itemslistField definition of each entry. Required for list.
aspectRatioslayoutAspect ratio presets offered by the zone editor.
defaultZoomlocationInitial zoom level of the map.
choicesstring, list of stringPick values from a list provided by an integration. See Choices.
visible_whenAll top-level fieldsShow the field only for some values of other fields. See Conditional fields.

Unknown attributes are rejected at upload time. There is no label attribute: the form uses the option key as the label unless you provide one in translations.

Conditional fields​

visible_when shows a field only while other fields have one of the listed values. Use it when one option switches between alternative sets of options:

{
"options_schema": {
"source": { "type": "string", "enum": ["listing", "listings"], "default": "listing", "order": 1 },
"estate_id": {
"type": "string",
"required": true,
"visible_when": { "source": ["listing"] },
"order": 2
},
"max_listings": {
"type": "number",
"default": 10,
"visible_when": { "source": ["listings"] },
"order": 3
}
}
}
  • Each key names another top-level option: a string, number or boolean field that has no visible_when itself. Each value is a non-empty list of values. With several keys, all must match.
  • When the referenced option has no value, its default is compared.
  • A hidden field is not required, and the dashboard doesn't save its value. If a value is sent anyway, it is still validated.
  • visible_when is only allowed on top-level fields of options_schema.

Label the values of an enum with values in the option's translations.

Duration​

If you declare a numeric duration option, its value, in seconds, sets how long the widget plays. See Widget duration.

References​

A ref field lets the user pick an existing resource. The collection value names the resource type, optionally followed by filters:

CollectionPicks
mediasAny media file
medias|type:imageImages only
medias|type:videoVideos only
playlistsA playlist, used by the layout component

When the player receives the widget, Castmill replaces the stored ID with the full resource. A media reference becomes an object with a files map (keyed by thumbnail, preview and poster), which you bind with [@target]. See Media references.

Nested maps and lists​

map and list fields group related values. For example, a list of labelled links:

{
"options_schema": {
"links": {
"type": "list",
"items": {
"type": "map",
"schema": {
"label": { "type": "string", "required": true },
"url": { "type": "url", "required": true }
}
}
}
}
}

Bind the entries with options.links, for example as the items of a paginated-list, or with array access such as options.links[0].label.

Choices​

A choices block turns a string field, or a list of strings, into a picker whose entries come from a list provided by the widget's integration, or from a built-in list.

{
"options_schema": {
"calendar_id": {
"type": "string",
"required": true,
"order": 1,
"choices": { "list": "calendars", "search": true }
},
"photos": {
"type": "list",
"items": { "type": "string" },
"order": 2,
"choices": {
"list": "images",
"depends_on": ["calendar_id"],
"display": "grid",
"multiple": true,
"ordered": true,
"max": 30
}
}
}
}
AttributeRequiredDescription
listYesName of the choice list.
displayNolist (default, label and description), cards (thumbnail, label and description) or grid (thumbnail tiles).
searchNoShows a search box; the provider receives the query.
multipleList fieldsAllows several values. Required on list fields; not allowed on string fields.
orderedNoWith multiple, the user can reorder the selection.
min, maxNoSelection bounds. Require multiple.
depends_onNoOption keys the provider needs. The field is disabled until they have values. Keys must exist and must not form a cycle.

choices is allowed only on top-level fields of options_schema. A widget that declares choices must have an integration whose fetcher implements the choices callback, unless all of its choice fields use built-in lists. See Data integrations.

The built-in feeds list​

The feeds list contains the organization's data feeds and needs no integration:

{
"options_schema": {
"feed": {
"type": "string",
"required": true,
"choices": { "list": "feeds", "search": true }
}
}
}

The player then receives the feed content as the widget's data. See Reading a data feed.

Data schema​

data_schema describes the data your template reads with data. bindings, usually produced by an integration or a feed. It uses the same field definitions as options_schema, without choices.

{
"data_schema": {
"headline": { "type": "string", "default": "No news yet" },
"items": {
"type": "list",
"items": {
"type": "map",
"schema": {
"title": { "type": "string" },
"pubDateFormatted": { "type": "string" }
}
}
}
}
}

When Castmill sends the widget to a player, it fills every missing top-level data key with its default. Use this to give the template sensible content before the first fetch completes.

tip

Use the object form ({ "type": "string" }) for every top-level data_schema field so defaults can be applied.

Aspect ratio​

Set aspect_ratio when your design only works at fixed proportions:

{ "aspect_ratio": "16:9" }

The value is a "width:height" string such as "16:9", "9:16", "4:3" or "1:1". When the playlist or layout zone has different proportions, the player letterboxes the widget: it scales the widget to the largest size that fits and leaves empty bars on the remaining sides. Omit aspect_ratio to let the widget fill any container, which is preferable for designs built with flexbox and em units.

Icons​

icon and small_icon identify the widget in the catalog and in playlists. Each accepts:

  • A path relative to widget.json inside an uploaded package, for example "assets/icons/menu.svg". Castmill serves it from /widget_assets/<slug>/assets/icons/menu.svg.
  • An absolute https:// URL or a path starting with /.
  • A data: URI.
  • A short text symbol, displayed as a glyph.

Use an SVG with viewBox="0 0 64 64" for icon (displayed at about 64 by 64 pixels) and a simpler version for small_icon (about 32 by 32 pixels). If a relative path does not match a file in the package, the icon is removed.

Assets​

An uploaded widget can be a ZIP package instead of a single widget.json. The package contains widget.json at its root and an assets/ folder:

cafe-menu.zip
├── widget.json
└── assets/
├── icons/
│ ├── icon.svg
│ └── small-icon.svg
├── fonts/
│ └── Lato-Regular.woff2
└── images/
└── background.jpg

Declare the files in an assets object, grouped by category. Paths are relative to widget.json:

{
"assets": {
"icons": {
"main": { "path": "assets/icons/icon.svg" }
},
"fonts": {
"body": { "path": "assets/fonts/Lato-Regular.woff2", "name": "Lato" }
},
"images": {
"background": { "path": "assets/images/background.jpg" }
}
}
}

Castmill stores the files: under /widget_assets/<slug>/ for organization widgets, and in public storage for network widgets. Fonts are loaded automatically before the widget starts, under the family name given in name (derived from the file name if omitted). Use that name in your styles:

{
"type": "text",
"name": "headline",
"opts": { "text": { "key": "options.title" } },
"style": { "font-family": "Lato, sans-serif", "font-size": "4em" }
}

Reference a declared file anywhere in the widget, for example in the template or the icon, with a {{asset:category.name}} placeholder. Castmill replaces it with the stored file's absolute URL when you upload the package, so it can also be the default of a url option. A placeholder can be a whole value or part of one, such as a CSS url():

{
"type": "image",
"name": "background",
"opts": { "url": "{{asset:images.background}}" },
"style": { "background-image": "url({{asset:images.pattern}})" }
}

A placeholder that doesn't name a declared file in the package is rejected. The icon can also be the file's path, such as assets/icons/icon.svg.

See the overview for upload limits.

Translations​

translations localizes the catalog entry and the configuration form. Keys are locale codes; each entry can override the name, description, option labels, the labels of enum values (values) and editable text labels:

{
"translations": {
"en": {
"name": "Cafe menu",
"description": "Menu board with prices and daily specials.",
"options": {
"title": {
"label": "Title",
"description": "Heading shown above the menu",
"placeholder": "Today's specials"
},
"accent": { "label": "Accent color" },
"layout": {
"label": "Layout",
"values": { "list": "List", "grid": "Grid" }
}
},
"editable": {
"Footer note": "Footer note"
}
},
"es": {
"name": "Menú de cafetería",
"options": {
"title": { "label": "Título" },
"accent": { "label": "Color de acento" }
},
"editable": {
"Footer note": "Nota al pie"
}
}
}
}

The dashboard looks up the user's locale first, then en, then the untranslated value (the widget name, the field's description or placeholder, the option key, or the enum value). Keys under editable are the label values of editable texts.