Create the composer.json:
{
"autoload":{
"psr-4":{
"App\\": "app",
"Windwalker\\": "vendor/windwalker"
}
},
"require": {
"windwalker/renderer": "2.*",
"illuminate/view": "4.*"
}
}
Here, i set the namespace for my work environment: App and Windwalker to use in my initial load.
The require pull the libs.
Now composer install(if you did not have) && composer update(if you updated) && composer auto-load
Create a folder init and write blade.php:
<?php
use Windwalker\Renderer\BladeRenderer;
$paths = array('./view');
$renderer = new BladeRenderer($paths, array('cache_path' => './cache'));
Set the path to your view folder and to a cache folder.
<?php
require 'vendor/autoload.php';
require 'init/blade.php';
$data = ['title' => 'Nice!'];
$html = $renderer->render('index', $data);
echo $html;
Create index.blade.php file in view folder.
@section('title')
@if( isset($title) )
{{ $title }}
@else
Without Title
@endif
@stop
<html>
<head>
<title>@yield('title')</title>
</head>
<body>
<p>Body</p>
@include('footer')
</body>
</html>
I created a footer.blade.php file to show the include.Check this on: Github
References:
http://asika.windspeaker.co/post/3975-use-blade-template-engine-outside-laravel
https://packagist.org/packages/philo/laravel-blade
Nenhum comentário:
Postar um comentário