#Is it possible to have custom images for blocks? It's kind of hard to define meaningful names
9 messages · Page 1 of 1 (latest)
Hi @vagrant kernel - yes! You can change the block image by adding an imageURL to the block config:
const QuoteBlock: Block = {
slug: 'Quote',
imageURL: 'https://google.com/path/to/image.jpg',
imageAltText: 'A nice thumbnail image to show what this block looks like',
fields: [
{
name: 'quoteHeader',
type: 'text',
required: true,
},
{
name: 'quoteText',
type: 'text',
},
]
};
Regarding the order of blocks, this will be the same order as they are defined in. We usually put them in alphabetical order, you can do whatever suits you best.
{
name: 'layout',
type: 'blocks',
minRows: 1,
maxRows: 20,
blocks: [
// This same order will be used in the admin
Accordion,
Banner,
Form,
QuoteBlock
]
}
]
How about use relative path from /src/assets in imageURL?
const QuoteBlock: Block = {
slug: 'Quote',
imageURL: './assets/image.jpg', <<= ???
imageAltText: 'A nice thumbnail image to show what this block looks like',
fields: [
{
name: 'quoteHeader',
type: 'text',
required: true,
},
{
name: 'quoteText',
type: 'text',
},
]
};
@fallen locust did you manage to do a relative path?
@ripe finch @fallen locust I do it like this
where is your thumbnails folder located?
It's a relative path from the block file definition
oh, got it.. thanks :D
I'm struggling to get relative imageURLs to work. Following the solution from @devout latch , i get this error during importmap generation:
TypeError [ERR_UNKNOWN_FILE_EXTENSION]: Unknown file extension ".png"
As i guess that using relative images instead of absolute URLs would be the primary use case for this, i'd be glad to update the public docs at https://payloadcms.com/docs/fields/blocks#block-configs, if someone points me to a working solution.