Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/youknowriad/blocky

Fastest way to create a WordPress block.
https://github.com/youknowriad/blocky

Last synced: 3 months ago
JSON representation

Fastest way to create a WordPress block.

Awesome Lists containing this project

README

        

# Blocky

The fast way to create WordPress blocks. No more hard JavaScript files, or weird PHP registration. Just create a `block.json` file and generate your block code.

# Why?

The WordPress block API is very powerful, it's very flexible and allows any kind of block you can think about. That flexibility and power comes at the cost of simplicity. A higher level API could be built around it to achieve 80% of the use-cases and won't require any React or PHP expertise. Just define your block name, its markup, its attributes and be done with it.

# Usage

1- Create a block.json file like this:

```js
// example/rich.json
{
//This is the block name.
"name": "example/rich",

// Define the attributes (or the editable properties of your blocks)
// Only provide a type and a name.
"attributes": {
"content": {
"type": "string"
}
},

// You can use any core block supports.
"supports": {
"color": {
"link": true
},
"typography": {
"fontSize": true,
"lineHeight": true
}
},

// Define the template/view of your block.
// This is a JSX like template that represents
// both the frontend and the backend of the block.
// You can use some helpers to annotate your template.
"view": ""
}
```

2- Build your block `npm run cli build example/plain.json`

This will generate the PHP and JS code required to run your block.
It generates an `index.php` file as an entry point for your block.

3- Update your plugin's php file to require the generated block's `index.php` file.

```php