# 🔪 Blade Templating

This is Leaf's implementation of Laravel's blade templating engine.

You can install leaf blade from composer:

composer require leafs/blade

After this, you simply need to initialize blade:

// initialising the package
$blade = new Leaf\Blade();

# Usage

To further understand blade, you can view the official documentation http://laravel.com/docs/5.8/blade (opens new window).

Leaf Blade only supports directory configurations, which can be passed as params on initialisation.

use Leaf\Blade;

// Blade("template dir", "cache dir");
$blade = new Blade('app/views', 'app/views/cache');

Not to worry, you can configure blade at a later time after initialisation.

$blade = new Leaf\Blade;

// somewhere, maybe in a different file
$blade->configure("app/views", "app/views/cache");

Since Blade is also bound directly to the Leaf object, you can directly do this

$app->blade->configure("app/views", "app/views/cache");

Now that this is done, we can render our blade template. This is done with make.

// don't forget to chain the render method
echo $blade->make('index', ['name' => 'Michael Darko'])->render(); // index.blade.php

Alternatively you can use the shorthand method render:

echo $blade->render('index', ['name' => 'Michael Darko']);

We can have this as our template index.blade.php

<!Doctype html>
        <title>{{ $name }}</title>
        <div class="container">{{ $name }}</div>

You can also extend Blade using the directive() function:

$blade->directive('datetime', function ($expression) {
    return "<?php echo with({$expression})->format('F d, Y g:i a'); ?>";

Which allows you to use the following in your blade template:

Current date: @datetime($date)

The Blade instances passes all methods to the internal view factory. So methods such as exists, file, share, composer and creator are available as well. Check out the original documentation (opens new window) for more information.