Skip to content

Hidden Field ​

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.

yaml
- name: unique_id
  label: Unique ID
  widget: hidden
  default: '{{uuid}}'
toml
[[fields]]
name = "unique_id"
label = "Unique ID"
widget = "hidden"
default = "{{uuid}}"
json
{
  "name": "unique_id",
  "label": "Unique ID",
  "widget": "hidden",
  "default": "{{uuid}}"
}
js
{
  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.

yaml
- name: author_name
  label: Author Name
  widget: hidden
  default: '{{author-name}}'
toml
[[fields]]
name = "author_name"
label = "Author Name"
widget = "hidden"
default = "{{author-name}}"
json
{
  "name": "author_name",
  "label": "Author Name",
  "widget": "hidden",
  "default": "{{author-name}}"
}
js
{
  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.

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

TIP

If you want the path to use the slug generated by the CMS, you can use the permalink_field collection option instead of a Hidden field. It fills the permalink property from the preview_path option each time an entry is saved, so the site is built at the same path the CMS links to. Remove the permalink field from the fields option in that case, because the CMS leaves the property alone when a field of the same name is defined.