Fields

Add/modify fields

How to create a field

Create file

Add a yml field file in fields directory.

layouts/
└── partials/
    └── admin/
        └── fields/

Simple widget

{{- $args := dict
  "label" (i18n "admin.fields.audio.mp3.label")
  "name" "mp3"
  "type" "audio"
  -}}
{{ partial "admin/widgets/file.js" $args }}

List or Object widget

{{- $pin := cond (or (eq site.Params.admin.cms "decapcms") (eq site.Params.admin.cms "sveltiacms")) "location" "coordinates" -}}
{{- $fields := slice 
  "street" 
  "zipcode" 
  "city" 
  "country_code"
  $pin -}}

# This line allows you to modify the fields via the parameters
{{- $fields = partial "admin/func/GetFields.html" (dict "field" . "fields" $fields) -}}

{{- $args := dict 
  "label" (i18n "admin.fields.address.label")
  "name" "address"
  "collapsed" true
  "fields" $fields
  -}}

{{ partial "admin/widgets/object.js" $args }}

Add or remove fields in object field

/config/_default/params.yaml

In this example, we set two fields (title and text with markdown) for the Hero field.

params:
  admin:
    fields:
      # Array of available fields for a fields
      # e.g with hero field
      hero:
        fields:
          - title
          - text_markdown
          # e.g with nested fields
          - image:
              fields:
                - image_src
                - image_alt

Markdown editor

The markdown fields below read their editor settings from params, so a project can enlarge the editor, open the raw markdown or change the toolbar without overriding the field.

/config/_default/params.yaml

params:
  admin:
    fields:
      text_markdown:
        minimal: false
        modes: "['rich_text', 'raw']"
        buttons: "['bold', 'italic', 'link', 'bulleted-list', 'numbered-list']"
  • minimal: true keeps the editor compact: Sveltia CMS caps it at 240 px and scrolls past that, Decap CMS shrinks it to the smallest height. false lets it grow with the content.
  • modes: rich_text, raw, or both. With both, the toolbar shows a switch, and the editor opens in the first mode listed.
  • buttons: the formatting buttons of the rich text toolbar. See the Sveltia CMS and Decap CMS documentation for the names.
  • editor_components: the components the editor can insert. body offers them all by default, the CMS’s own image and code-block plus the enabled shortcodes. Set, a field offers only the ones listed, so name the shortcodes too: "['button']" drops the image and the code block and keeps the button shortcode, "[]" removes them all.

Write `modes`, `buttons` and `editor_components` as a quoted string

The value is copied as is into the CMS config. A YAML list such as [rich_text, raw] comes out as a single, invalid mode named rich_text raw.

FieldUsed byminimalbuttonsmodeseditor_components
text_markdownThe text of most blocks, the banner and credit config filestrue['bold', 'italic', 'link', 'bulleted-list']['rich_text']None
title_markdownOpt-in, a title that takes bold and italictrue['bold', 'italic']['rich_text']None
quoteThe quote and testimonials blocks, the blockquote shortcodetrue['bold', 'italic', 'link']['rich_text']None
creditImage credits, the figure and video shortcodestrue['link']['rich_text']None
legalThe fine print under the submit button of the form block, the legal notice of a real estatetrue['bold', 'italic', 'link']['rich_text']None
llmsThe body of the llms.txt and llms-full.txt files, in the config collectionfalseAll['raw']None
bodyThe body of an entrytrueAll['rich_text']All
contentsThe inner text of the details and alert-block shortcodestrue['bold', 'italic', 'link']['rich_text']['blank_link']
CMSWhat applies
Decap CMS, Netlify CMS, Sveltia CMSminimal, modes, buttons and editor_components
Static CMSminimal, modes and buttons. Hugolify registers no shortcodes there, so editor_components is left out.
CloudCannonminimal only: true gives a resizable editor 150 px high. There is no raw mode.
Pages CMSNone. The rich-text editor has its own Editor / Source switch.
TinaCMSNone. The rich-text toolbar has its own raw markdown button.

Collapse blocks

The blocks of an entry arrive unfolded. Fold them to their summary, so a long page reads as a list of sections:

/config/_default/params.yaml

params:
  admin:
    fields:
      blocks:
        collapsed: true

Options of a select field

options replaces the values a select field offers. It works on every select field, not only grid and theme: align, breakpoints, direction, layout, offset, scrollsnap, vertical_align…

/config/_default/params.yaml

params:
  admin:
    fields:
      align:
        options: [start, center]

Written next to the field in a fields list, the options apply to that list only:

params:
  admin:
    blocks:
      cta:
        fields:
          - title
          - ui:
              - theme: { options: [light, dark] }

The languages and the countries offer the whole ISO lists, which come from the theme. options narrows them down the same way:

/config/_default/params.yaml

params:
  admin:
    fields:
      country_code:
        options: [FR, BE, CH, LU]

Default map position

The location field opens on Paris. Move it with a GeoJSON point — longitude first, then latitude:

/config/_default/params.yaml

params:
  admin:
    widgets:
      map:
        default: '{"type": "Point", "coordinates": [4.8357, 45.7640]}'

The fields of a config file

New in v2

Each file of the config collection ships its own set of fields. admin.files.<name>.fields replaces that set, without touching the files list — so changing the fields of one file no longer means restating every other:

/config/_default/params.yaml

params:
  admin:
    files:
      footer:
        fields: [newsletter, cta, blocks]
      seo:
        fields: [title, description, image_seo]

Available on footer, seo, credit and banner. Left undefined, each keeps the fields the module declares — respectively title, text_area, cta, blocks, title, description, image_seo, twitter, text_markdown, and text_markdown, state.

New fields

New in v2
FieldPurpose
ratioMedia aspect ratio, 1 being square
scrollsnapBreakpoints at which items scroll sideways (none, sm, md, lg, xl, all)
selected_sourceChoose block items manually or by taxonomy
vertical_alignVertical text alignment (start, center, end)
image.src_mobileDedicated mobile image, used by the hero
weight_selectThe v1 stepped weight select, kept as an opt-in
languagesLanguages a person or the organization works in, among the 183 of ISO 639-1, stored as codes
area_servedAreas the organization serves, published as typed (FR, Worldwide)
number_of_employeesHeadcount of the organization, a number or a range (150-250)
date_foundedFounding date of the organization, a year or a full date
date_expiryEnd date of a job offer, stored as expiryDate
educationDegrees of a person: title, school, year and category (degree or certificate), published as hasCredential and alumniOf. In the default fields of persons; hugolify-theme-persons lists it in the sidebar of the person page
alternate_name, awards, head_office, other_places, same_as, schema_type, schema_logo, schema_email, contact_page, slogan, vat_id, tax_idThe organization and its structured data, see Structured data

Other additions: blocks on the persons and products collections, firstname and lastname on persons, a file input for form fields, and an optional format on the datetime widget for Decap and Sveltia storage.

Renamed and changed fields

v1v2
Draftis_draftdraft
Background colourbackground-color.ymlbackground_color.yml
Weightselect (10, 20, 30…)number input (min: 1, integer)
Appearanceflat at the root of the blockgrouped under ui
Country of an addresscountry, typed incountry_code, a select of the 249 ISO 3166-1 countries, shown in the language of the page

If you relied on the stepped weight select, the previous behaviour is preserved in a separate field:

admin/fields/weight_select.yml

A country typed in before stays on the page as long as the address has no country_code.

A title built from other fields

New in v2 Only available with Sveltia CMS

title_page reads a compute template and hands it to the compute widget. Left undefined, it stays the regular text input, which is also what a project running any other CMS gets.

The persons collection does this by default: a person is named after their first and last name, so the page title is derived rather than asked for, and never typed twice.

/config/_default/params.yaml

params:
  admin:
    collections:
      persons:
        fields:
          - draft
          - title_page: { i18n: duplicate, compute: '{{fields.firstname}} {{fields.lastname}}' }
          - firstname
          - lastname
          - body

List of Hugolify fields

See fields in repository