View template engine of PHP extracted from Laravel
PHP
Latest commit a3fe5dc Dec 18, 2016 @XiaoLer add autoloader file
Permalink
Failed to load latest commit information.
src add autoloader file Dec 18, 2016
.gitignore base compiler Oct 21, 2015
.php_cs base compiler Oct 21, 2015
LICENSE update license Jan 7, 2016
README.md fix doc Nov 12, 2016
composer.json add installation Oct 22, 2015

README.md

Blade

【简体中文】

This is a view templating engine which is extracted from Laravel. It's independent without relying on Laravel's Container or any others.

Installation

With Composer, you just need to run

composer require xiaoler/blade

If you haven't use composer, you should add all the files in folder src to your project folder, and then require them in your code.

Usage

<?php
$path = ['/view_path'];         // your view file path, it's an array
$cachePath = '/cache_path';     // compiled file path

$compiler = new \Xiaoler\Blade\Compilers\BladeCompiler($cachePath);

// you can add a custom directive if you want
$compiler->directive('datetime', function($timestamp) {
    return preg_replace('/(\(\d+\))/', '<?php echo date("Y-m-d H:i:s", $1); ?>', $timestamp);
});

$engine = new \Xiaoler\Blade\Engines\CompilerEngine($compiler);
$finder = new \Xiaoler\Blade\FileViewFinder($path);

// if your view file extension is not php or blade.php, use this to add it
$finder->addExtension('tpl');

// get an instance of factory
$factory = new \Xiaoler\Blade\Factory($engine, $finder);

// render the template file and echo it
echo $factory->make('hello', ['a' => 1, 'b' => 2])->render();

You can enjoy almost all the features of blade with this extension. However, remember that some of exclusive features are removed.

You can't:

  • use @inject @can @cannot @lang in a template file
  • add any events or middleawares

Documentation: http://laravel.com/docs/5.3/blade

Thanks for Laravel and it authors. That is a great project.