Jens Segers on

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.

Webmentions

Tweet about this blog post and you will appear below!