https://github.com/themeplate/blocks
Easy server-side-rendered blocks
https://github.com/themeplate/blocks
wordpress wordpress-blocks wordpress-gutenberg
Last synced: about 2 months ago
JSON representation
Easy server-side-rendered blocks
- Host: GitHub
- URL: https://github.com/themeplate/blocks
- Owner: ThemePlate
- License: gpl-3.0
- Created: 2022-06-10T08:39:13.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2025-03-02T07:55:44.000Z (about 1 year ago)
- Last Synced: 2025-03-02T08:25:51.129Z (about 1 year ago)
- Topics: wordpress, wordpress-blocks, wordpress-gutenberg
- Language: PHP
- Homepage:
- Size: 196 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ThemePlate Blocks
## Usage
```php
use ThemePlate\Blocks\BlockType;
/** https://developer.wordpress.org/reference/classes/wp_block_type/__construct/#parameters */
$config = array(
'namespace' => 'my-blocks',
'template' => '/path/to/render.php',
);
( new BlockType( 'Custom Block', $config ) )->fields( $list )->init();
/** >= 1.6.0 */
( new BlockType( __DIR__ . '/tests/example' ) )->init()
```
> Check out [example block](/tests/example)
### Restrict inner blocks and prefill components
```php
$config = array(
'allowed_blocks' => array(
'core/image',
'core/heading',
'core/paragraph',
),
'template_blocks' => array(
array( 'core/image', array() ),
array( 'core/heading', array( 'placeholder' => 'Insert title here' ) ),
array( 'core/paragraph', array( 'placeholder' => 'Insert content copy' ) ),
),
);
( new BlockType( 'My custom block', $config ) )->fields( $list )->init();
/** >= 1.6.0 */
// return in the config.php file beside block.json
return $config;
```
> Disable nested blocks by setting `$config` key `inner_blocks` to `false`
### Structured *(Bulk)* Definition
```
/path/to/blocks/
├── first-block/
│ ├── block.json // >= 1.6.0
│ ├── config.php
│ └── markup.php
├── second-block/
├── block.json // >= 1.6.0
├── config.php
└── markup.php
```
```php
use ThemePlate\Blocks\CustomBlocks;
( new CustomBlocks( 'My Blocks', '/path/to/blocks' ) )->init();
/** >= 1.6.0 */
( new CustomBlocks( '/path/to/blocks' ) )->init()
```
#### */block/block.json
```json
{
...
https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/
...
}
```
#### */block/config.php
```php
fields( $list );
/** >= 1.6.0 */
return array(
...
/** https://developer.wordpress.org/reference/classes/wp_block_type/__construct/#parameters */
...
);
```
#### */block/markup.php
```php
>
```