Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sebastiansulinski/blade
Blade templates outside of Laravel.
https://github.com/sebastiansulinski/blade
blade-directives blade-template blade-template-engine php-template-engine
Last synced: about 1 month ago
JSON representation
Blade templates outside of Laravel.
- Host: GitHub
- URL: https://github.com/sebastiansulinski/blade
- Owner: sebastiansulinski
- License: mit
- Created: 2016-07-01T20:29:34.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-02-29T08:52:19.000Z (almost 5 years ago)
- Last Synced: 2024-04-14T20:58:03.050Z (8 months ago)
- Topics: blade-directives, blade-template, blade-template-engine, php-template-engine
- Language: PHP
- Size: 12.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Blade
Package to allow you use blade templates outside of Laravel.[![Build Status](https://travis-ci.org/sebastiansulinski/blade.svg?branch=master)](https://travis-ci.org/sebastiansulinski/blade)
### Usage instructions
Blade constructor takes 4 arguments, 2 of which are optional:
```php
$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)
Filesystem $events = null: // instance of the Illuminate\Events\Filesystem (optional)
```With new instance of the Blade class you can call the `view()` methods the same way as from within Laravel using [view()](https://laravel.com/docs/master/views) helper.
```php
$blade = new Blade(
realpath(__DIR__ . '/../resources/views'),
realpath(__DIR__ . '/../resources/cache')
);
```#### Passing variables
```php
$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
```php
$blade->view()->exists('test');
```#### Sharing data with all views
```php
$blade->share('user', $user);
```#### View composers
```php
$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](https://laravel.com/docs/master/blade)
```php
// index.blade.php@extends('template.layout')
@section('content')
Hallo {{ $user->name }}
@endsection
```#### Example
```php
// /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
Title
@yield('content')
// /resources/views/pages/index.blade.php
@extends('template.layout')
@section('content')
Hallo {{ $user->name }}
@endsection
```