Gutenberg as a design system (part 2)
In [part 1](https://publishing-project.rivendellweb.net/?p=790075&preview=true) we discussed how to build variations for specific components. We'll now see how we can create templates ready for the user to fill and either use as-is or modify it when needed. ## Block Templates The first type of template is at the block level. This allows the creation of complex blocks without having to do much on the PHP side. We first import our tools like normal, the i18n utilities, registerBlockType and [InnerBlocks](https://github.com/WordPress/gutenberg/tree/master/packages/block-editor/src/components/inner-blocks#README.md) ```js import { __ } from '@wordpress/i18n'; import { registerBlockType } from '@wordpress/blocks'; import { InnerBlocks } from '@wordpress/block-editor'; ``` We then define our template in a constant. This is the structure of the block that we want to have. We can use attributes of the blocks in the template like the placeholder attribute that we use in the example to tell the user what we expect her to enter in each block. ```js const BLOCK_TEMPLATE = [ [ 'core/image', {} ], [ 'core/heading', { placeholder: 'Book Title' } ], [ 'core/heading', { placeholder: 'Book Author' } ], [ 'core/paragraph', { placeholder: 'Summary' } ], ]; ``` The block registration is no different than a custom block. The only difference is that our `InnerBlocks` declaration uses a template attribute with our `BLOCK_TEMPLATE` definition as the parameter. In this example, we've chosen to lock the template so the user cannot move the inner blocks nor they can add any new block to the template. The "save" methods remains the same. ```js registerBlockType( 'rivendellweb-blocks/example-06', { title: __('Example 06', 'rivendellweb-blocks'), category: 'rivendellweb-blocks', icon: 'translation', edit: ( { className } ) => { return (
Lorem ipsum sit amet, consectetur adipiscing elit
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
