image
Typetype ImageField = {label: stringname: stringtype: 'image'list?: boolean// See https://tina.io/docs/extending-tina/overview/ for customizing the UIui?: {label?: stringdescription?: stringcomponent?: FC<any> | string | nullparse?: (value: string, name: string, field: F) => anyformat?: (value: string, name: string, field: F) => anyvalidate?(value: string,allValues: any,meta: any,field: UIField<F, Shape>): string | undefined | void}}
export default defineConfig({//...schema: {collections: [{name: 'posts',label: 'Blog Posts',path: 'content/posts',format: 'mdx',fields: [{type: 'image',label: 'Hero image',name: 'imgSrc',},// ... other fields],},],},})// ...
Please see the media docs for how to set up media in your site.
If you need to customize how an image is formatted in a field, you can use the format
& parse
options.
//tina/config.ts// fields// ...{type: "image",name: "heroImg",label: "Hero Image",ui: {format(value) {//add leading slash to value if it doesnt existreturn value.startsWith("/") ? value : `/${value}`;},parse(value) {//remove leading slash if it existsreturn value.startsWith("/") ? value.slice(1) : value;},}}
You can read more about format
& parse
here.
Last Edited: September 12, 2024
© TinaCMS 2019–2024