A library for using Laravel Blade templates in WordPlate.

Overview

blade

blade

A library for using Laravel Blade templates in WordPress/WordPlate.

Build Status Coverage Status Total Downloads Latest Version License

Installation

Require this package, with Composer, in the root directory of your project.

$ composer require fiskhandlarn/blade

Usage

Render

Use helper function blade:

blade('index', ['machine' => 'Voight-Kampff']);

(This renders and echoes the template /resources/views/index.blade.php and caches it to /storage/views.)

... or instantiate Blade by passing the folder(s) where your view files are located, and a cache folder. Render a template by calling the render method.

use Fiskhandlarn\Blade;

$blade = new Blade(get_stylesheet_directory() . '/views', get_stylesheet_directory() . '/cache');

echo $blade->render('index', ['machine' => 'Voight-Kampff']);

Render with data from a controller class

Use helper function blade_controller:

blade_controller('index', 'Index');

(This renders and echoes the template /resources/views/index.blade.php with data generated from App\Controllers\Index.)

Controller classes must extend Fiskhandlarn\BladeController.

... or use the renderController method on a Blade object:

echo $blade->renderController('index', 'Index');

You can also pass additional data (this won't override properties from the controller though):

blade_controller('index', 'Index', ['lifespan' => "A coding sequence cannot be revised once it's been established."]);
echo $blade->renderController('index', 'Index', ['lifespan' => "A coding sequence cannot be revised once it's been established."]);

See soberwp/controller for more info on how to use controllers.

Supported features:

Unsupported features:

Untested features:

Unnecessary features:

Custom directive

Create a custom directive with helper function blade_directive:

format('Y-m-d H:i:s'); ?>"; });">
blade_directive('datetime', function ($expression) {
    return "format('Y-m-d H:i:s'); ?>";
});

... or use the directive method on a Blade object:

format('Y-m-d H:i:s'); ?>"; });">
$blade->directive('datetime', function ($expression) {
    return "format('Y-m-d H:i:s'); ?>";
});

Then you can use the directive in your templates:

{{-- In your Blade template --}}
@php $dateObj = new DateTime('2019-11-01 00:02:42') @endphp
@datetime($dateObj)

Custom composer

Create a custom composer with helper function blade_composer:

// Make variable available in all views
blade_composer('*', function ($view) {
    $view->with(['badge' => 'B26354']);
});

... or use the composer method on a Blade object:

// Make variable available in all views
$blade->composer('*', function ($view) {
    $view->with(['badge' => 'B26354']);
});

Share variables

Share variables across all templates with helper function blade_share:

// Make variable available in all views
blade_share(['badge' => 'B26354']);

... or use the share method on a Blade object:

$blade->share(['badge' => 'B26354']);

Extension

The Blade class passes all method calls to the internal compiler (see documentation) or view factory (see documentation for info on exists, first and creator).

Cache

If WP_DEBUG is set to true templates will always be rendered and updated.

Multisite

If run on a WordPress Multisite the cached files will be separated in subfolders by each site's blog id.

Filters

Use the blade/view/paths filter to customize the base paths where your templates are stored. (Default value is /resources/views.)

add_filter('blade/view/paths', function ($paths) {
    $paths = (array) $paths;

    $paths[] = get_stylesheet_directory() . '/views';

    return $paths;
});

Use the blade/cache/path filter to customize the cache folder path. (Default value is /storage/views.)

add_filter('blade/cache/path', function ($path) {
    $uploadDir = wp_upload_dir();
    return $uploadDir['basedir'] . '/.bladecache/';
});

Use the blade/cache/path filter to control creation of cache folder. (Default value is true.)

add_filter('blade/cache/create', '__return_false');

Use the blade/controller/namespace filter to customize the controller namespace. (Default value is App\Controllers.)

add_filter('blade/controller/namespace', function () {
    return 'MyApp\Controllers';
});

License

GNU GPL 3.0+

You might also like...
Simple transactional email classes/templates for Laravel 5 mailables
Simple transactional email classes/templates for Laravel 5 mailables

Tuxedo Tuxedo is an easy way to send transactional emails with Laravel's Mail classes, with the templates already done for you. Contents Installation

A package to easily make use of Iconic icons in your Laravel Blade views.
A package to easily make use of Iconic icons in your Laravel Blade views.

Blade Iconic A package to easily make use of Iconic icons in your Laravel Blade views. For a full list of available icons see the SVG directory. Iconi

A package to easily make use of Simple Icons in your Laravel Blade views.
A package to easily make use of Simple Icons in your Laravel Blade views.

Blade Simple Icons A package to easily make use of Simple Icons in your Laravel Blade views. For a full list of available icons see the SVG directory.

Laravel blade directives and php helpers for serverside rendered content, based on browser window size WITHOUT css

Laravel Window Size and Breakpoints Laravel blade directives and php helpers for server side rendered content, based on browser window size WITHOUT cs

Storybook for Laravel Blade 🚀

Blast — Storybook for Laravel Blade 🚀 What is Blast? Blast is a low maintenance component library using Storybook Server, built to integrate into you

Cagilo - a set of simple components for use in your views Laravel Blade.

Cagilo - a set of simple components for use in your views Laravel Blade. Official Documentation Documentation for Cagilo can be found on its we

Useful blade components and functionality for most Laravel projects.

laravel-base Note: Package is still in early stages of development, so functionality is subject to change. LaravelBase is a package I've created to pr

An opinionated blade template formatter for Laravel that respects readability
An opinionated blade template formatter for Laravel that respects readability

blade-formatter An opinionated blade template formatter for Laravel that respects readability Online Demo Features Automatically Indents markup inside

Laravel Livewire (TALL-stack) form generator with realtime validation, file uploads, array fields, blade form input components and more.
Laravel Livewire (TALL-stack) form generator with realtime validation, file uploads, array fields, blade form input components and more.

TALL-stack form generator Laravel Livewire, Tailwind forms with auto-generated views. Support Contributions Features This is not an admin panel genera

Comments
  • Fatal error: Uncaught Error: Call to private Dotenv\Repository\Adapter\EnvConstAdapter::__construct()

    Fatal error: Uncaught Error: Call to private Dotenv\Repository\Adapter\EnvConstAdapter::__construct()

    Hi,

    We have an error when we updated Wordplate to version 9.1 because the package updated vlucas/dotenv to 5.0 so we have : Fatal error: Uncaught Error: Call to private Dotenv\Repository\Adapter\EnvConstAdapter::__construct() from context 'Illuminate\Support\Env' in C:\laragon\www\wordplate\vendor\illuminate\support\Env.php:58 Stack trace: #0 C:\laragon\www\wordplate\vendor\illuminate\support\Env.php(81): Illuminate\Support\Env::getRepository() #1 C:\laragon\www\wordplate\vendor\illuminate\support\helpers.php(276): Illuminate\Support\Env::get('WP_PREFIX', 'wp_') #2 C:\laragon\www\wordplate\public\wp-config.php(56): env('WP_PREFIX', 'wp_') #3 C:\laragon\www\wordplate\public\wordpress\wp-load.php(42): require_once('C:\\laragon\\www\\...') #4 C:\laragon\www\wordplate\public\wordpress\wp-admin\admin.php(34): require_once('C:\\laragon\\www\\...') #5 C:\laragon\www\wordplate\public\wordpress\wp-admin\themes.php(10): require_once('C:\\laragon\\www\\...') #6 {main} thrown in C:\laragon\www\wordplate\vendor\illuminate\support\Env.php on line 58

    opened by menegain-mathieu 6
  • Update branch alias

    Update branch alias

    It is common to point the branch alias to the next major or minor version before it it released. It can be used as a "beta" version until the stable version is released.

    https://getcomposer.org/doc/articles/aliases.md

    This way users can install version ^1.0 if they set minimum-stability to dev in their composer.json file.

    opened by vinkla 2
Releases(v0.6.2)
Owner
Half centaur, half minotaur. Time traveler.
null
Use Blade templates without the full Laravel framework

blade Use Laravel Blade templates as a standalone component without the full Laravel framework Full documentation is available at http://duncan3dc.git

Craig Duncan 138 Dec 7, 2022
API Blueprint Renderer for Laravel, customizable via Blade templates

API Blueprint Renderer for Laravel This Laravel package Blueprint Docs renders your API Blueprint. It comes with a standard theme that you can customi

Michael Schmidt-Voigt 225 Sep 16, 2022
Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views

Blade UI Kit is a set of renderless components to utilise in your Laravel Blade views. In all essence, it's a collection of useful utilities, connecting the dots between different parts of the TALL stack. It was made for Blade, Laravel's powerful templating engine.

Blade UI Kit 1.2k Jan 5, 2023
Vim syntax highlighting for Blade templates.

vim-blade Vim syntax highlighting for Blade templates (Laravel 4+). This plugin contributes to vim-polyglot language pack. Installation Using vim-plug

Jason Walton 194 Dec 1, 2022
Create inline partials in your Blade templates with ease

Create inline partials in your Blade templates with ease. This package introduces a new @capture directive that allows you to capture small parts of y

Ryan Chandler 27 Dec 8, 2022
Blade Snip allows you to use parts of a blade template multiple times. Basically partials, but inline.

Blade Snip Blade Snip allows you to use parts of a blade template multiple times. Basically partials, but inline: <div class="products"> @snip('pr

Jack Sleight 18 Dec 4, 2022
Create Laravel views (blade template) using 'php artisan' command-line interface

About LaraBit Have you ever wonder to create Laravel views (Blade Templates) using the same type of artisan commands that you usually use to create ne

Ragib MRB 5 Oct 15, 2021
A Laravel Code Generator based on your Models using Blade Template Engine

Laravel Code Generator is a PHP Laravel Package that uses Blade template engine to generate code for you. The difference between other code generators

Victor Yoalli 59 Dec 5, 2022
Source code behind the Laracasts Larabit: Creating and Using Custom Blade Directives

This is the source code behind the Laracasts Larabit: Creating and Using Custom Blade Directives, and features all of the files and code available in that video.

Andrew Schmelyun 1 Nov 12, 2021
Use Laravel's Blade templating engine outside of Laravel.

Use Laravel's Blade templating engine outside of Laravel. This package provides a standalone version of Laravel's Blade templating engine for use outs

Ryan Chandler 22 Jan 2, 2023