Jens Segers on Aug 29 2015

Using Blade outside of Laravel

For me, Laravel's Blade templating engine is one of the best templating engines I have ever used. But wouldn't it be nice to use Blade outside of a Laravel project?

blade

Blade allows you to quickly write views without the whole process of learning a complicated syntax, as most of it is just PHP code lead by an @ sign. As you know, most of the illuminate components can be used outside the Laravel framework, but the view component requires a bit of bootstrapping before you can use it.

That's why I decided to put this bootstrapping process in a package that you can pull in from packagist. Simply install it using composer:

composer require jenssegers/blade

Once you have the package installed. You can create a Blade instance by passing it the folder(s) where your view files are located, and a cache folder:

use Jenssegers\Blade\Blade;

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

echo $blade->make('homepage', ['name' => 'John Doe']);

And that's it! Now you can start using Blade in your Slim or Symfony projects, without having to worry about the internal container or service providers. Feel free to contribute on github.


Comments

Babacar Cissé Dia 3 weeks ago

Nice man! Happy to read this article from your blog!


rohmanhm 1 year ago

can you add support for laravel 5.3?


Chris Andrew 2 years ago

Nice! I'll probably make an adapter for this for my framework.


angelhvargas 2 years ago

How could I use the HTML facade and URL facade????