-
Notifications
You must be signed in to change notification settings - Fork 33
07 Adding new examples
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
This repository offers a script to create a new example using any existing example as a template.
- Run
npm run create-example:copy
- Choose the example you want to use as a template for your new example
- Add a meaningful name for your example
- Add a description for your example
- Add tags for your example
The script will handle most of the necessary modifications, so your new example follows the conventions of this repository.
See an example of running npm run create-example:copy
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