The simple yet powerful Blade templating engine ported to WordPress for themes developers.
Before proceeding to installation, please make sure your environment met these requirements:
composer require devmium/blade-wp
use Devmium\Blade\WordPressBlade;
// Initialize WordPressBlade instance
$blade = WordPressBlade::getInstance();
// Render a specific template
WordPressBlade::render($view, $with = []);
// Register a custom directive
WordPressBlade::directive($name, $handler);
After initialing WordPressBlade service (usually in theme's functions.php file), it will automatically attempt to load template file first from theme/views/{TEMPLATE_FILE}.blade.php then fallback to theme/{TEMPLATE_FILE}.php
Giving the following directory structure:
theme
- assets/
- includes/
- views/
- single.blade.php
- archive.blade.php
- index.blade.php
- index.php
- style.css
Assuming a single post request (is_single() === true), the service will load theme/views/single.blade.php. If theme/views/single.blade.php doesn't exist, the service will fallback to theme/single.php and then theme/index.php
@wp_posts()
{{ the_title() }}
{!! the_content() !!}
@wp_empty()
{{ 'No posts' }}
@wp_end()
TBD
You can browse Blade's documentation directly from Laravel documentation.