Use Blade Template Engine Outside of Laravel

Written by Simon Asika on

file

Blade is a powerful php template engine which created by Laravel. There is an integration method to use it outside Laravel.

We use Windwalker Renderer

Usage

Add this to composer.json require block:

{
    "require": {
        "windwalker/renderer": "2.*",
        "illuminate/view": "4.*"
    }
}

And run composer update.

Then we can use this code to render *.blade.php files:

use Windwalker\Renderer\BladeRenderer;

$paths = array('/your/tmpl/path');

$renderer = new BladeRenderer($paths, array('cache_path' => __DIR__ . '/cache'));

$renderer->render('foo.bar', $data); // Will render foo/bar.blade.php

Windwalker Renderer also supports Twig and Mustache:

use Windwalker\Renderer\TwigRenderer;

$renderer = new TwigRenderer($paths);

$renderer->render('foo', $data);

Full documentation please see Windwalker Renderer


2016-11-11 updated

I wrote a Blade compatible template engine called Edge, you can write blade syntax without any Laravel dependencies. Just try it.

Control Tools

WS-logo