devmium/blade-wp

Blade package for WordPress

dev-master 2019-04-30 22:50 UTC

This package is auto-updated.

Last update: 2024-09-29 05:02:16 UTC


README

The simple yet powerful Blade templating engine ported to WordPress for themes developers.

Requirements

Before proceeding to installation, please make sure your environment met these requirements:

Installation

composer require devmium/blade-wp

Usage

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

Examples

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

Built-in WordPress custom directives

Simple loop:

@wp_posts()
    {{ the_title() }}
    {!! the_content() !!}
@wp_empty()
    {{ 'No posts' }}
@wp_end()

Notes

TBD

Blade documentation

You can browse Blade's documentation directly from Laravel documentation.