-
Notifications
You must be signed in to change notification settings - Fork 35
Adding new examples
JuanMa Garrido edited this page Jan 7, 2025
·
4 revisions
This guide will show you how to add new block development examples. There are several different ways to accomplish this. You can create a brand new example, copy an existing one in this repository, or clone an example from an external repository.
This repo can create a new, blank example using the @wordpress/create-block
package and a custom external template provided by this repository.
- Run
npm run create-example:new -- example-slug
changingexample-slug
to the name of the plugin you wish to create. - Add any additional flags that are supported by the
@wordpress/create-block
package after the--
There are currently 3 variations
supported by the custom template:
-
static
- scaffolds a plugin with a single block that renders statically by saving its markup to the database (default) -
dynamic
- scaffolds a plugin with a single block that renders dynamically on the front end via PHP -
non-block
- scaffolds a plugin that loads a single JavaScript file. Use this variant, for example, such as block variations or SlotFill.
Example
This example will create a plugin called my-great-example-{generated-hex-code}
with a single block that renders dynamically.
npm run create-example:new -- my-great-example --variant dynamic
If you have another repo containing a plugin with an example you'd like to add as new example of this repo:
- Go to the
plugins
folder andgit clone
your repo with your example there - Go inside your project's folder
- Delete the
.git
folder - Do the proper changes to adapt your plugin to follow the conventions of this repository