Skip to content

Adding new examples

JuanMa edited this page Nov 3, 2023 · 4 revisions

Table of Contents

Adding a new example to this repo

Using npm run create-example:new to scaffold a new blank example

This repo can create a new, blank, example using the @wordpress/create-block package and a custom external template provided by this repository.

  1. Run npm run create-example:new -- example-slug changing example-slug to the name of the plugin you wish to create.
  2. 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:

  1. static - scaffolds a plugin with a single block that renders statically by saving it's markup to the database (default)
  2. dynamic - scaffolds a plugin with a single block that renders dynamically on the front end via PHP
  3. 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

Using npm run create-example:copy to use another example as template

This repo offers you a script to create a new example using any of already existing examples as a template.

  1. Run npm run create-example
  2. Choose the example you want to use as a template for your new example
  3. Add a meaningful name for your example
  4. Add a description for your example
  5. Add tags for your example

The script will take care of most of the modifications needed so your new example follow the conventions of this repo.

See an example of running npm run create-example:copy

Cloning an example from another repo

If you have another repo containing a plugin with an example you'd like to add as new example of this repo:

  1. Go to the plugins folder and git clone your repo with your example there
  2. Go inside your project's folder
  3. Delete the .git folder
  4. Do the proper changes to adapt your plugin to follow the conventions for this repo
Clone this wiki locally