PHPackages                             themeplate/blocks - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. themeplate/blocks

ActiveLibrary[Templating &amp; Views](/categories/templating)

themeplate/blocks
=================

ThemePlate server side rendered block

v1.16.0(1y ago)065GPL-3.0-onlyPHPPHP ^7.4|^8.2

Since Jun 23Pushed 1y ago1 watchersCompare

[ Source](https://github.com/ThemePlate/Blocks)[ Packagist](https://packagist.org/packages/themeplate/blocks)[ RSS](/packages/themeplate-blocks/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (2)Versions (19)Used By (0)

ThemePlate Blocks
=================

[](#themeplate-blocks)

Usage
-----

[](#usage)

```
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

[](#restrict-inner-blocks-and-prefill-components)

```
$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

[](#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

```

```
use ThemePlate\Blocks\CustomBlocks;

( new CustomBlocks( 'My Blocks', '/path/to/blocks' ) )->init();

/** >= 1.6.0 */
( new CustomBlocks( '/path/to/blocks' ) )->init()
```

#### \*/block/block.json

[](#blockblockjson)

```
{
	...
	https://developer.wordpress.org/block-editor/reference-guides/block-api/block-metadata/
	...
}
```

#### \*/block/config.php

[](#blockconfigphp)

```
