Scaffolding a block
The command npm run scaffold is available to scaffold a new block. Once run it will ask several questions
in order to setup a new block.
? What is the name of the block, as it would appear in the block selector?
? What is the slug of the block?
? What is a description of the block?
? Is this block built for Nova?
? What category does the block belong to?
? Use @wordpress/icons for the icon?
? Add optional keywords separated by a comma.
? Will this block use post meta?
? Will this block use InnerBlocks?
? Will this block has any editor styles?Once completed the new block will scaffold. It will create a block folder in the blocks/global directory
and a test in the tests/blocks directory.
Context Notes
- Block Name. Capital case.
- The block slug is automatically created from the block name unless otherwise defined. All lowercase, and will force hyphens vs spaced.
- Description of the block to display in the
InspectorControlssidebar. - The "Is this block built for Nova?", if true, will support the
nova_render_callbackmethod in the block'sblock.phpfile. - All PMC blocks should be scaffolded into the
pmccategory (a custom category). - The dashicon question supports all of the built-in Dashicons (opens in a new tab) by default. Additionally supports icons via the
@wordpress/iconspackage. - "Add options keywords". Add keywords that are searchable using the slash command or the inserter search field.
- "Will this block use post meta?" will add the
meta.jsonfile as well as the necessary hooks/helpers in theedit.jsfile. - The "Will this block use InnerBlocks?", if true, will add the necessary
<InnerBlocks.Content />callback to the block registration allowing for$contentto be made available to therender_callbackmethod(s). - Finally, if styles will be needed an
edit.scssfile will be added
Look at the block breakdown for additional context.
Adding New Features
👩💻
Call for contribution on these updates.
New features can be added or unused or redudnant features can be removed as needed. Some features that have been requested but not implemented are (but are not limited to):
- Add additional feature defaults including
InspectorControlsorBlockControlsto name a couple. - Add the ability to define the supports object values.