[ad_1]
Hi,
I noticed that WP has 2 available formats to define InnerBlocks formats – I’d like to know if anyone is aware if there is any function that I could use to convert between those.
Here’re examples:
In blocks.json to define example I have to use this format:
"example": {
"innerBlocks": [
{
"name": "core/heading",
"attributes": {
"content": "<h2>Heading</h2>",
"level": 2
}
},
{
"name": "core/paragraph",
"attributes": {
"content": "<p>Paragraph</p>"
}
}
]
}However to recreate same in <InnerBlocks /> component I have to use this format:
<InnerBlocks
template={ [
[
'core/heading',
{
level: 2,
content: '<h2>Heading</h2>',
},
],
[
'core/paragraph',
{
content: '<p>Paragraph</p>',
},
],
] }
/>At the end I’d like to reuse code from block.json by simply importing it to JS file and using it like this:
import blockJson from '../block.json';
const blockExample = blockJson.example;
// ... rest of code
<InnerBlocks template={ blockExample.innerBlocks } />
