Skip to content
Sveltia CMS
Esc
↑↓navigate↵open⌘Jpreview
On this page

Hidden Field

Store hidden values in Sveltia CMS that users cannot view or edit.

The Hidden field type is used to store values that should not be visible or editable by users in the entry form. It is typically used for metadata or system-generated values.

User Interface

None. A hidden field does not render any UI components in the entry form.

Data Type

Any value assigned programmatically or via default settings.

Data Validation

No specific data validation is applied to the Hidden field, as its value is not user-editable.

Options

In addition to the common field options, the Hidden field supports the following options:

Required Options

widget

  • Type: string
  • Default: string

Must be set to hidden.

default

  • Type: any
  • Default: ""

The default value for the hidden field. It’s used when creating a new entry, and when opening an existing entry that doesn’t have the field, such as one written before the field was added to the configuration. Any data type is accepted (string, number, boolean, object, array, etc.) as long as it can be serialized to the collection’s data format (YAML, JSON, TOML, etc.).

TOML does not support null values, so avoid using null as the default value when the collection’s data format is set to TOML.

A string default value supports the following template tags, which are filled in when a new entry draft is created:

  • {{locale}}: The current locale code when i18n support is enabled, e.g. en or fr. The tag requires i18n support for the collection or file; otherwise, a configuration error is reported, since there is no locale to fill it with.
  • {{datetime}}: The current date/time in ISO 8601 format.
  • {{uuid}}, {{uuid_short}} and {{uuid_shorter}}: A random UUID or its shorter version, just like the slug template tags.
  • {{author-email}}, {{author-login}} and {{author-name}}: The signed-in user’s email, login name and display name, respectively, just like commit message tags. These tags don’t work with the local development workflow because the user is not authenticated via a Git backend.

The default value is also applied again in the following cases:

  • When an entry is duplicated, or a List item holding the field is duplicated or pasted, the field gets its default value again, with any tags filled in anew, so the copy doesn’t share a UUID or a date with its original.
  • When a locale is enabled for an existing entry, a translatable field (i18n: true) whose default contains a tag gets the tags filled in for the new locale, e.g. {{locale}} becomes the new locale code. If the default has no tag, the value is copied from the default locale like any other field’s.

String transformations can be applied in this option. Any other tag, such as {{title}} or {{slug}}, is replaced with an empty string. The slug isn’t known until the entry is saved, so to store a path containing it, use the permalink_field option. To keep a template tag for your static site generator, escape it with a backslash. See the example below.

Examples

Embedding UUID in a Hidden Field

This example shows how to create a hidden field that automatically generates and stores a UUID for each entry. This can be useful for uniquely identifying entries.

- name: unique_id
  label: Unique ID
  widget: hidden
  default: '{{uuid}}'
[[fields]]
name = "unique_id"
label = "Unique ID"
widget = "hidden"
default = "{{uuid}}"
{
  "name": "unique_id",
  "label": "Unique ID",
  "widget": "hidden",
  "default": "{{uuid}}"
}
{
  name: 'unique_id',
  label: 'Unique ID',
  widget: 'hidden',
  default: '{{uuid}}',
}

Embedding the Author’s Name in a Hidden Field

This example shows how to create a hidden field that automatically captures the name of the user creating the entry.

- name: author_name
  label: Author Name
  widget: hidden
  default: '{{author-name}}'
[[fields]]
name = "author_name"
label = "Author Name"
widget = "hidden"
default = "{{author-name}}"
{
  "name": "author_name",
  "label": "Author Name",
  "widget": "hidden",
  "default": "{{author-name}}"
}
{
  name: 'author_name',
  label: 'Author Name',
  widget: 'hidden',
  default: '{{author-name}}',
}

Passing a Template to a Static Site Generator

This example shows how to store an Eleventy permalink template that Eleventy fills in at build time. The backslash before the curly braces keeps Sveltia CMS from processing the template tag, and is removed from the saved value, which is portfolio/{{ title | slugify }}/index.html.

- name: permalink
  label: Permalink
  widget: hidden
  default: 'portfolio/\{{ title | slugify }}/index.html'
[[fields]]
name = "permalink"
label = "Permalink"
widget = "hidden"
default = "portfolio/\\{{ title | slugify }}/index.html"
{
  "name": "permalink",
  "label": "Permalink",
  "widget": "hidden",
  "default": "portfolio/\\{{ title | slugify }}/index.html"
}
{
  name: 'permalink',
  label: 'Permalink',
  widget: 'hidden',
  default: 'portfolio/\\{{ title | slugify }}/index.html',
}

Was this page helpful?