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.
- name: image
label: Image
widget: image[[fields]]
name = "image"
label = "Image"
widget = "image"{
"name": "image",
"label": "Image",
"widget": "image"
}{
name: 'image',
label: 'Image',
widget: 'image',
}Output example:
image: /uploads/photo.jpgimage = "/uploads/photo.jpg"{
"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.
- name: image
widget: object
fields:
- { name: src, widget: image }
- { name: alt, widget: string }[[fields]]
name = "image"
widget = "object"
[[fields.fields]]
name = "src"
widget = "image"
[[fields.fields]]
name = "alt"
widget = "string"{
"name": "image",
"widget": "object",
"fields": [
{ "name": "src", "widget": "image" },
{ "name": "alt", "widget": "string" }
]
}{
name: 'image',
widget: 'object',
fields: [
{ name: 'src', widget: 'image' },
{ name: 'alt', widget: 'string' },
],
}Output example:
image:
src: /uploads/photo.jpg
alt: A beautiful sunset[image]
src = "/uploads/photo.jpg"
alt = "A beautiful sunset"{
"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.
- name: gallery
label: Gallery
widget: image
multiple: true
min: 2
max: 5
accept: image/webp[[fields]]
name = "gallery"
label = "Gallery"
widget = "image"
multiple = true
min = 2
max = 5
accept = "image/webp"{
"name": "gallery",
"label": "Gallery",
"widget": "image",
"multiple": true,
"min": 2,
"max": 5,
"accept": "image/webp"
}{
name: 'gallery',
label: 'Gallery',
widget: 'image',
multiple: true,
min: 2,
max: 5,
accept: 'image/webp',
}Output example:
gallery:
- /uploads/photo1.webp
- /uploads/photo2.webp
- /uploads/photo3.webpgallery = ["/uploads/photo1.webp", "/uploads/photo2.webp", "/uploads/photo3.webp"]{
"gallery": ["/uploads/photo1.webp", "/uploads/photo2.webp", "/uploads/photo3.webp"]
}