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: imagetoml
[[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.jpgtoml
image = "/uploads/photo.jpg"json
{
"image": "/uploads/photo.jpg"
}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/webptoml
[[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.webptoml
gallery = ["/uploads/photo1.webp", "/uploads/photo2.webp", "/uploads/photo3.webp"]json
{
"gallery": ["/uploads/photo1.webp", "/uploads/photo2.webp", "/uploads/photo3.webp"]
}