N
N
naneri2015-10-22 22:52:20
Laravel
naneri, 2015-10-22 22:52:20

How to use Laravel Blade outside of Laravel as a class?

The instructions of the Laravel Blade package say how to connect the template engine:

require 'vendor/autoload.php';

use Philo\Blade\Blade;

$views = __DIR__ . '/views';
$cache = __DIR__ . '/cache';

$blade = new Blade($views, $cache);
echo $blade->view()->make('hello')->render();

And how to do it in order to use it like in Laravel . Do not initialize a variable in each controller ... In the constructor of the parent controller, registration of the template engine is also not a desire to include. How to be?
View::make('template');

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2015-10-22
@naneri

take pimple (or php-di), and generally read about dependency inversion.

A
Aleksey Ratnikov, 2015-10-22
@mahoho

Grab Blade with composer:
And then in code:

$blade = new \Philo\Blade\Blade("/path/to/blade/views", "/path/to/blade/cache");
echo $blade->view()->make('templateName', $params)->render(); //здесь как в laravel

You can wrap this call in the view() function: //similarly as in Laravel:
function view($view, $params = []){
    $blade = new \Philo\Blade\Blade("/path/to/blade/views", "/path/to/blade/cache");
    $blade = $this->loadCompiler();
    return $blade->view()->make($view, $params)->render();
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question