snicco/blade-bridge

Use v8.x of Laravel's Blade templating engine in WordPress. Fully tested and production ready.

v1.9.0 2023-09-20 12:36 UTC

README

codecov Psalm Type-Coverage Psalm level PhpMetrics - Static Analysis PHP-Versions

This package allows using the blade template engine without the fullstack laravel framework.

100% tested with full support for all features of blade, including view composers.

This package must be used together with snicco/templating.

Installation

composer require snicco/blade-bridge

Usage

Creating a BladeViewFactory

To start rendering .blade.php views with the template engine of snicco/templating we need to create a BladeViewFactory and pass it to the template engine.

use Snicco\Bridge\Blade\BladeStandalone;
use Snicco\Bridge\Blade\BladeViewFactory;
use Snicco\Component\Templating\Context\ViewContextResolver;
use Snicco\Component\Templating\TemplateEngine;

/**
* @var ViewContextResolver $view_context_resolver
*/
$view_context_resolver = /* Check the documentation of snicco/templating */

$blade = new BladeStandalone(
    __DIR__.'/cache/blade', // directory path for the compiled templates
    [
       __DIR__.'/views',
       __DIR__.'/templates',
    ], // An array of directories where views are located
    $view_context_resolver
);


$blade->boostrap();

/**
* @var BladeViewFactory
*/
$blade_view_factory = $blade->getBladeViewFactory();

$template_engine = new TemplateEngine(
    $blade_view_factory
);

You can now render any .blade.php views with the template engine.

Blade features

All features of blade 8.x can be used. Please consult the documentation.

There are some directives which are disabled by this package by default and will throw an exception when used because they are not decoupled from Laravel's global helper functions.

You can always enable them again with your own implementation using Blade::directive().

The following directives are disabled:

  • auth
  • guest
  • method
  • csrf
  • service
  • env
  • production
  • can
  • cannot
  • canany
  • dd
  • dump
  • lang
  • choice
  • error
  • inject

Contributing

This repository is a read-only split of the development repo of the Snicco project.

This is how you can contribute.

Reporting issues and sending pull requests

Please report issues in the Snicco monorepo.

Security

If you discover a security vulnerability, please follow our disclosure procedure.