Title: New createBlocksFromInnerBlocksTemplate Block API
Author: Isabel Brison
Published: November 18, 2020

---

 [  ](https://profiles.wordpress.org/isabel_brison/) [Isabel Brison](https://profiles.wordpress.org/isabel_brison/)
3:22 am _on_ November 18, 2020     
Tags: [5.6 ( 85 )](https://make.wordpress.org/core/tag/5-6/),
[block-editor ( 145 )](https://make.wordpress.org/core/tag/block-editor/), [dev-notes ( 655 )](https://make.wordpress.org/core/tag/dev-notes/)

# New createBlocksFromInnerBlocksTemplate Block API

There is a new BlockBlock Block is the abstract term used to describe units of markup
that, composed together, form the content or layout of a webpage using the WordPress
editor. The idea combines concepts of what in the past may have achieved with shortcodes,
custom HTML, and embed discovery into a single consistent API and user experience.
APIAPI An API or Application Programming Interface is a software intermediary that
allows programs to interact with each other and share data in limited, clearly defined
ways. in WordPress 5.6: `createBlocksFromInnerBlocksTemplate`, with which you can
create blocks from `InnerBlocks` template.

Given an array of InnerBlocks templates or Block Objects, it returns an array of
created Blocks from them.
It handles the case of having InnerBlocks as Blocks by
converting them to the proper format to continue recursively.

This is especially useful for handling `block variations`, transformations and creation/
replacement of blocks which use `InnerBlocks template`.

An example that would create new blocks from a block variation using InnerBlocks’
template and replace the block’s content is:

    ```notranslate
    import { InnerBlocks } from '@wordpress/block-editor';
    import { useDispatch } from '@wordpress/data';
    import { __ } from '@wordpress/i18n';
    import { Button, ToolbarGroup, ToolbarButton } from '@wordpress/components';
    import { BlockControls, useBlockProps } from '@wordpress/block-editor';
    import { createBlocksFromInnerBlocksTemplate } from '@wordpress/blocks';

    function MyEditBlock( { clientId } ) {
        const { replaceInnerBlocks } = useDispatch( 'core/block-editor' );
        const variation = {
            name: 'my-variation',
            title: __( 'My variation' ),
            innerBlocks: [
                [ 'core/paragraph', { content: 'Hello' } ],
                [ 'core/paragraph', { placeholder: __( 'Write title…' ) } ],
            ],
        };
        const onClick = () => {
            replaceInnerBlocks(
                clientId,
                createBlocksFromInnerBlocksTemplate( variation.innerBlocks )
            );
        };
        return (
            &lt;div { ...useBlockProps() }>
                &lt;BlockControls>
                    &lt;ToolbarGroup>
                        &lt;ToolbarButton onClick={ onClick }>
                            &lt;span>Change InnerBlocks&lt;/span>
                        &lt;/ToolbarButton>
                    &lt;/ToolbarGroup>
                &lt;/BlockControls>
                &lt;InnerBlocks />
            &lt;/div>
        );
    }
    ```

See the [pull request](https://github.com/WordPress/gutenberg/pull/25829) for implementation
details and more.

Props to [@ntsekouras](https://profiles.wordpress.org/ntsekouras/) for writing this
dev notedev note Each important change in WordPress Core is documented in a developers
note, (usually called dev note). Good dev notes generally include a description 
of the change, the decision that led to this change, and a description of how developers
are supposed to work with that change. Dev notes are published on Make/Core blog
during the beta phase of WordPress release cycle. Publishing dev notes is particularly
important when plugin/theme authors and WordPress developers need to be aware of
those changes.In general, all dev notes are compiled into a Field Guide at the beginning
of the release candidate phase..

[#5-6](https://make.wordpress.org/core/tag/5-6/), [#block-editor](https://make.wordpress.org/core/tag/block-editor/),
[#dev-notes](https://make.wordpress.org/core/tag/dev-notes/)

### Share this:

 * [  Threads ](https://make.wordpress.org/core/2020/11/18/new-createblocksfrominnerblockstemplate-block-api/?share=threads)
 * [  Mastodon ](https://make.wordpress.org/core/2020/11/18/new-createblocksfrominnerblockstemplate-block-api/?share=mastodon)
 * [  Bluesky ](https://make.wordpress.org/core/2020/11/18/new-createblocksfrominnerblockstemplate-block-api/?share=bluesky)
 * [  X ](https://make.wordpress.org/core/2020/11/18/new-createblocksfrominnerblockstemplate-block-api/?share=x)
 * [  Facebook ](https://make.wordpress.org/core/2020/11/18/new-createblocksfrominnerblockstemplate-block-api/?share=facebook)
 * [  LinkedIn ](https://make.wordpress.org/core/2020/11/18/new-createblocksfrominnerblockstemplate-block-api/?share=linkedin)

# Post navigation

[← Changes to Toolbar components in WordPress 5.6](https://make.wordpress.org/core/2020/11/18/changes-to-toolbar-components-in-wordpress-5-6/)

[Dev Chat Agenda: 18th November 2020: →](https://make.wordpress.org/core/2020/11/18/dev-chat-agenda-18th-november-2020/)