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 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.


angelhvargas 3 years ago

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

Chris Andrew 3 years ago

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

rohmanhm 2 years ago

can you add support for laravel 5.3?

Babacar Cissé Dia 1 year ago

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

kshux 1 year ago

You sir... I love you!

Muhammad Baiquni 7 months ago

I've been using your HMVC on CodeIgniter. How can I integrate this Blade template into HMVC?

Thank you