Download the PHP package morningtrain/wp-blocks without Composer
On this page you can find all versions of the php package morningtrain/wp-blocks. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download morningtrain/wp-blocks
More information about morningtrain/wp-blocks
Files in morningtrain/wp-blocks
Package wp-blocks
Short Description A package for loading WordPress blocks with support for Blade templates
License MIT
Informations about the package wp-blocks
Morningtrain\WP\Blocks
A Morningtrain package for working with WordPress blocks more easily.
📋 Table of Contents
[[TOC]]
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 theblock.json
files
Getting Started
To get started install the package as described below in Installation.
To use the tool have a look at Usage
Installation
Install with composer
Dependencies
morningtrain/php-loader
PHP Loader is used to load and initialize all Hooks
Usage
Loading the block directory
To initialize the package and/or to load blocks from a path use Blocks::setup
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!
The view will have the following vars: $block
, $attributes
, $content
and $blockProps
Example:
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
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:
Credits
- Mathias Munk
- All Contributors
Testing
License
The MIT License (MIT). Please see License File for more information.