Blade templates outside of laravel.
224
3
2
Package Data
Maintainer Username: sebastiansulinski
Maintainer Contact: info@ssdtutorials.com (Sebastian Sulinski)
Package Create Date: 2016-07-01
Package Last Update: 2020-02-29
Language: PHP
License: MIT
Last Refreshed: 2024-11-23 03:24:23
Package Statistics
Total Downloads: 224
Monthly Downloads: 3
Daily Downloads: 0
Total Stars: 3
Total Watchers: 2
Total Forks: 0
Total Open Issues: 0

Blade

Package to allow you use blade templates outside of Laravel.

Build Status

Usage instructions

Blade constructor takes 4 arguments, 2 of which are optional:

$viewPaths: // either a string or array of paths where your views will be fetched from
$cachePath: // string representing the path to the cache directory (to store cached version of the views)
Container $app = null: // instance of the Illuminate\Container\Container (optional)
Dispatcher $events = null: // instance of the Illuminate\Events\Dispatcher (optional)

With new instance of the Blade class you can call the view() methods the same way as from within Laravel using view() helper.

$blade = new Blade(
    realpath(__DIR__ . '/../resources/views'),
    realpath(__DIR__ . '/../resources/cache')
);

Passing variables

$user = User::find(1);

$blade->view('index', compact('user'));

$blade->view('index', ['user' => $user]);

$blade->view('index')->with('user', $user);

Determining if a view exists

$blade->view()->exists('test');

Sharing data with all views

$blade->share('user', $user);

View composers

$blade->view()->composer('dashboard', function(View $view) {

    $user = new stdClass;
    $user->name = 'Martin';

    $view->with('user', $user);

});

$blade->view('dashboard');
// has instance of $user available

Blade vew template

Use blade view templates the same way as with Laravel

// index.blade.php

@extends('template.layout')

@section('content')

<h1>Hallo {{ $user->name }}</h1>

@endsection

Example

// /public/index.php

$blade = new Blade(
    realpath(__DIR__ . '/../resources/views'),
    realpath(__DIR__ . '/../resources/cache')
);

$user = User::find(1);

echo $blade->view('pages.index', compact('user'));


// /resources/views/template/layout.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Title</title>
</head>
<body>

<div class="row">

    <div class="column">

        @yield('content')

    </div>

</div>

</body>
</html>


// /resources/views/pages/index.blade.php

@extends('template.layout')

@section('content')

<h1>Hallo {{ $user->name }}</h1>

@endsection