Skip to content

Image Field

The Image field type allows users to upload and manage images within the CMS. It’s basically an alias of the File field type but limited to image files.

The widget property for this field type is image.

See the File field documentation for details on the UI, data type, and available options.

Examples

Standard Image Field

This example shows a basic Image field.

yaml
- name: image
  label: Image
  widget: image
toml
[[fields]]
name = "image"
label = "Image"
widget = "image"
json
{
  "name": "image",
  "label": "Image",
  "widget": "image"
}
js
{
  name: 'image',
  label: 'Image',
  widget: 'image',
}

Output example:

yaml
image: /uploads/photo.jpg
toml
image = "/uploads/photo.jpg"
json
{
  "image": "/uploads/photo.jpg"
}

Image Field with Alt Text

To include additional metadata such as alt text for accessibility, you can use an object field to group the image source and alt text together.

yaml
- name: image
  widget: object
  fields:
    - { name: src, widget: image }
    - { name: alt, widget: string }
toml
[[fields]]
name = "image"
widget = "object"
[[fields.fields]]
name = "src"
widget = "image"
[[fields.fields]]
name = "alt"
widget = "string"
json
{
  "name": "image",
  "widget": "object",
  "fields": [
    { "name": "src", "widget": "image" },
    { "name": "alt", "widget": "string" }
  ]
}
js
{
  name: 'image',
  widget: 'object',
  fields: [
    { name: 'src', widget: 'image' },
    { name: 'alt', widget: 'string' },
  ],
}

Output example:

yaml
image:
  src: /uploads/photo.jpg
  alt: A beautiful sunset
toml
[image]
src = "/uploads/photo.jpg"
alt = "A beautiful sunset"
json
{
  "image": {
    "src": "/uploads/photo.jpg",
    "alt": "A beautiful sunset"
  }
}

In the future, we may add built-in support for alt text and other metadata directly within the Image field type.

Multiple Image Uploads with Restrictions

This example shows how to allow multiple image uploads using the multiple option, along with minimum and maximum limits and file type restrictions.

yaml
- name: gallery
  label: Gallery
  widget: image
  multiple: true
  min: 2
  max: 5
  accept: image/webp
toml
[[fields]]
name = "gallery"
label = "Gallery"
widget = "image"
multiple = true
min = 2
max = 5
accept = "image/webp"
json
{
  "name": "gallery",
  "label": "Gallery",
  "widget": "image",
  "multiple": true,
  "min": 2,
  "max": 5,
  "accept": "image/webp"
}
js
{
  name: 'gallery',
  label: 'Gallery',
  widget: 'image',
  multiple: true,
  min: 2,
  max: 5,
  accept: 'image/webp',
}

Output example:

yaml
gallery:
  - /uploads/photo1.webp
  - /uploads/photo2.webp
  - /uploads/photo3.webp
toml
gallery = ["/uploads/photo1.webp", "/uploads/photo2.webp", "/uploads/photo3.webp"]
json
{
  "gallery": ["/uploads/photo1.webp", "/uploads/photo2.webp", "/uploads/photo3.webp"]
}