How are block templates used in Gutenberg content editor?

How are block templates used in Gutenberg content editor?

Block templates are one of my favorite new features in Gutenberg. You can specify a list of blocks that automatically appear in the content editor, and you can customize what appears in each block by default. You can also lock the template so no additional blocks can be added. This is a great replacement for metaboxes in many cases.

How are ad units set in a Gutenberg template?

With Gutenberg, we simply pre-populate the content area with two ad blocks ( built with Advanced Custom Fields) and three paragraph blocks. Content editors can then dive right into content creation around the ad units. Here’s how you set the block template for posts:

How to limit the size of a block in Gutenberg?

With Gutenberg, we can limit the editor to just the “Quote” block. This allows the client to use the same UI for managing their blockquotes site-wide. When registering your post type, use the template parameter to specify an array of which blocks should appear. Including ‘template_lock’ => ‘all’ will prevent any changes to the layout.

Can a block template be used as a Metabox?

You can also lock the template so no additional blocks can be added. This is a great replacement for metaboxes in many cases. You can control the content structure without sacrificing the visual editing experience.

What are the keys for attributes in Gutenberg?

Each attribute’s key is the attribute name, and you must have the property type as a minimum. The type property can be any of the following; null, boolean, object, array, number, string, or integer. You can optionally provide the property default to define the starting value of your attribute.

How do you save a Gutenberg template for reuse?

To do this, select the three dots in the upper right corner. Under Editor, select Code Editor. Highlight and copy the code. Paste the code into a text editor and save it for reuse. When you’re ready to use the template, simply create a new post, switch to the code editor, and paste the code. I now have a new post that I can start adding content to.