JavaScript for WordPress › Forums › Gutenberg Development › Block Template using InnerBlocks (3 flexible columns containing custom block)
- This topic has 2 replies, 1 voice, and was last updated 5 years, 6 months ago by sm.
-
AuthorPosts
-
March 18, 2019 at 9:22 pm #98857smParticipant
I am trying to create a block template using InnerBlocks – it has a ‘columns’ block containing 3 variable-width columns as follows:
- Custom Block
- Paragraph Block with custom style
- Custom Block
If I don’t use the a custom block in columns 1 & 3, it works fine. However, it does not work if I use a custom block in any one of the columns.
Here is my code so far:
/** * Block dependencies */ import classnames from 'classnames'; import './style.scss'; import './editor.scss'; /** * Internal block libraries */ const { __ } = wp.i18n; const { registerBlockType, } = wp.blocks; const { InnerBlocks, } = wp.editor; const { Dashicon, } = wp.components; /** * Block template */ const MY_CUSTOM_BLOCK_TEMPLATE = [ [ 'core/columns', { columns: 3 }, [ [ 'core/column', {}, [ [ 'custom-block/custom-block'] ] ], [ 'core/column', {}, [ [ 'core/paragraph', { placeholder: 'Enter heading...', className: 'is-style-custom-style'} ] ] ], [ 'core/column', {}, [ [ 'custom-block/custom-block'] ] ], ] ] ]; /** * Register block */ export default registerBlockType( 'custom-blocks/custom-block-template', { title: __( 'Custom-Block-Template', 'custom-blocks' ), description: __( 'Add custom block template', 'custom-blocks'), category: 'layout', icon: { background: 'rgba(0, 133, 66)', src: 'align-none', }, keywords: [ __( 'Custom', 'custom-blocks' ), __( 'Template', 'custom-blocks' ), ], edit: props => { const { className, setAttributes } = props; return [ <div className={ classnames( className, ) } > <InnerBlocks template={MY_CUSTOM_BLOCK_TEMPLATE} /> </div> ]; }, save: props => { return ( <div className={ classnames( props.className, ) } > <InnerBlocks.Content /> </div> ); }, }, );
Also the folder/file structure is:
– custom-blocks
— custom-block (contains index.js, editor.scss, styles.scss etc.)
— custom-block-template (contains index.js, editor.scss, styles.scss etc.)
— index.jsimport “./i18n.js”; /** * Import custom blocks */ import “./custom-block”; import “./custom-block-template”;
Any help is appreciated. Thank you!
March 18, 2019 at 9:34 pm #98872smParticipantRemoved comment – added more details in original question.
March 19, 2019 at 9:32 pm #99068smParticipantI figured out the issue – the custom block namespace was not correct. I had mistakenly assumed that the custom block name in the template is “folder_name/block_name” instead of “namespace/block_name”. After I made the change, it works correctly now.
-
AuthorPosts
- You must be logged in to reply to this topic.