Question about Gutenberg transforms.to usage with multiple blocks
-
Hi,
I’m working on a custom block and using the
transformsAPI to allow it to convert into other blocks. The docs show that you can list multiple block types in theblocksarray, but I’m unsure how to handle different logic for each target.Here’s a simplified example:
registerBlockType( 'my/block', {
title: 'My Block',
category: 'widgets',
attributes: {
content: { type: 'string' },
},
transforms: {
to: [
{
type: 'block',
blocks: [ 'core/paragraph', 'core/heading' ],
transform: ( attributes ) => {
// How do I know if the user picked "Paragraph" or "Heading" here?
return createBlock( 'core/paragraph', {
content: attributes.content,
} );
},
},
],
},
} );My question:
- When I provide multiple block names in the
blocksarray, is there a way inside thetransformfunction to know which block type the user selected? - Or is the recommended approach to declare separate transform objects for each target block instead (one for
core/paragraph, one forcore/heading)?
I didn’t see this clarified in the Block Transforms documentation.
Thanks for any guidance!
- When I provide multiple block names in the
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
You must be logged in to reply to this topic.