PHPackages                             morningtrain/wp-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. morningtrain/wp-blocks

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

morningtrain/wp-blocks
======================

A package for loading WordPress blocks with support for Blade templates

v0.6.0(2y ago)21.3kMITPHPPHP ^8.0

Since Oct 22Pushed 2y ago4 watchersCompare

[ Source](https://github.com/Morning-Train/wp-blocks)[ Packagist](https://packagist.org/packages/morningtrain/wp-blocks)[ RSS](/packages/morningtrain-wp-blocks/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (9)Used By (0)

Morningtrain\\WP\\Blocks
========================

[](#morningtrainwpblocks)

A Morningtrain package for working with WordPress blocks more easily.

📋 Table of Contents
-------------------

[](#-table-of-contents)

\[\[*TOC*\]\]

Introduction
------------

[](#introduction)

This tool is made for organizing WordPress Gutenberg blocks!

This tool lets you:

- Load all blocks found in a directory
- Render Blade views by defining them as `renderView` in block meta
- Load PHP dependencies by placing `*.php` files next to the `block.json` files

Getting Started
---------------

[](#getting-started)

To get started install the package as described below in [Installation](#installation).

To use the tool have a look at [Usage](#usage)

### Installation

[](#installation)

Install with composer

```
composer require morningtrain/wp-blocks
```

Dependencies
------------

[](#dependencies)

### morningtrain/php-loader

[](#morningtrainphp-loader)

[PHP Loader](https://github.com/Morning-Train/php-loader) is used to load and initialize all Hooks

Usage
-----

[](#usage)

### Loading the block directory

[](#loading-the-block-directory)

To initialize the package and/or to load blocks from a path use `Blocks::setup`

```
use Morningtrain\WP\Blocks\Blocks;
// Tell Blocks where the built/compiled files are located
Blocks::setup(__DIR__ . "/public/build/blocks");

// To add another directory
Blocks::registerBlockDirectory(__DIR__ . "/public/build/blocks");
```

Using a View
------------

[](#using-a-view)

To serverside render a block using a Blade View set the custom `renderView` property.

You can also have custom PHP code dependency. By declaring `phpScript` the given script will be loaded alongside the registration of your block. This is especially useful when needing a View Composer.

Note the custom schema url!

```
{
    "$schema": "https://wp.cdn.mtra.in/default/schemas/block.json",
    "apiVersion": 3,
    "name": "foo/bar",
    "version": "0.1.0",
    "title": "Bar",
    "textdomain": "foo",
    "editorScript": "file:./index.js",
    "editorStyle": "file:./index.css",
    "style": "file:./style-index.css",
    "renderView": "my-view",
    "phpScript": "file:./script.php",
    "viewPhpScript": [
        "file:./view-script.php",
        "file:./view-script2.php"
    ],
    "editorPhpScript": "file:./editor-script.php"
}
```

The view will have the following vars: `$block`, `$attributes`, `$content` and `$blockProps`

Example:

```

    {{$attributes['title']}}
    {!! $content !!}

```

If you wish to view compose you may create a `*.php` file within your block folder. As long as it is a sibling to the `block.json` file and is not named `*.asset.php` then it will automatically be loaded.

Caching
-------

[](#caching)

If your environment is `production` then a cache containing all block files and their dependencies will be generated and used so that the server doesn't have to look for them on every request.

To clear this cache you can use the CLI command:

```
wp wp-blocks deleteCacheFiles
```

Credits
-------

[](#credits)

- [Mathias Munk](https://github.com/mrmoeg)
- [All Contributors](../../contributors)

Testing
-------

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~98 days

Recently: every ~109 days

Total

8

Last Release

981d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/278725?v=4)[morningtrain](/maintainers/morningtrain)[@morningtrain](https://github.com/morningtrain)

![](https://www.gravatar.com/avatar/dc62314c2179f47535e9ad94944210faf9dcab3601d340487bd79f21a6b654bf?d=identicon)[mrmoeg](/maintainers/mrmoeg)

---

Top Contributors

[![mrmoeg](https://avatars.githubusercontent.com/u/5990117?v=4)](https://github.com/mrmoeg "mrmoeg (66 commits)")

---

Tags

wordpressblocksgutenbergmorningtrain

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/morningtrain-wp-blocks/health.svg)

```
[![Health](https://phpackages.com/badges/morningtrain-wp-blocks/health.svg)](https://phpackages.com/packages/morningtrain-wp-blocks)
```

###  Alternatives

[palmiak/timber-acf-wp-blocks

Create Gutenberg blocks from Twig templates and ACF fields.

24872.5k1](/packages/palmiak-timber-acf-wp-blocks)[infinum/eightshift-libs

WordPress libs developed by Eightshift team to use in modern WordPress.

63118.9k3](/packages/infinum-eightshift-libs)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
