laraport / blade
Unofficial port of laravel's illuminate/view.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 5 226
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=5.4.0
- illuminate/view: ^4.2.17
- mikey179/vfsstream: ^1.6
Requires (Dev)
- phpunit/phpunit: 4.*
README
This php library is an unofficial port of the laravel (L4) blade templating engine. See illuminate/blade and the docs for more details. The reason for this port is so that developers may consume it in a standalone project or another framework without being forced to import the whole laravel framework.
Requires PHP 5.4 or greater.
Includes a few extras:
- Supports raw template string rendering.
- Supports custom file extensions.
- Cache path is optional.
Table of contents
Install
This package can be installed by requiring it via composer.
$ composer require laraport/blade
Usage
If you have consumed blade views in laravel (which i am sure you have), its now a cinch to consume it in a standalone project as well.
The laravel way
The usual laravel way is setting the view path and cache.
<?php require_once __DIR__ . '/vendor/autoload.php'; $path2views = __DIR__.'/path/to/views'; $path2cache = __DIR__.'/path/to/cache'; $Blade = new Laraport\Blade($path2views, $path2cache); $View = $Blade->make('welcome', ['name' => 'Alice']); echo $View->render();
which will render
__DIR__./path/to/views/welcome{.blade}.php
Without cache
One of the added feature is loading a view without setting up a cache directory. This uses vfsStream behind the scenes.
<?php require_once __DIR__ . '/vendor/autoload.php'; $Blade = new Laraport\Blade(__DIR__.'/path/to/views'); $View = $Blade->make('hello', ['name' => 'Bob']); echo $View->render();
which will render
__DIR__./path/to/views/hello{.blade}.php
without any cache.
Raw string templates
Another added feature is supporting raw string template rendering. This also uses vfsStream behind the scenes.
<?php require_once __DIR__ . '/vendor/autoload.php'; $View = Laraport\Blade::render('Hello {{ $name }}!', ['name' => 'Eve']); echo $View->render();
which will print out
Hello Eve!
Custom file extensions
You may also set custom file extensions for your blade view templates.
<?php require_once __DIR__ . '/vendor/autoload.php'; $Blade = new Laraport\Blade(__DIR__.'/path/to/views'); $Blade->withExtension('foo.bar'); $View = $Blade->make('custom', ['name' => 'Laravel']); echo $View->render();
Which will render one of
custom.foo.bar
,custom.blade.php
orcustom.php
, whichever is found.
You may add more than one extension if you so wish.
Shared data
Data may also be shared as globals for all your views.
<?php require_once __DIR__ . '/vendor/autoload.php'; $Blade = new Laraport\Blade(__DIR__.'/path/to/views'); $Blade->share('acme', 'baz'); $View = $Blade->make('foo'); echo $View->render();
$acme
will be available to all views.
Test
First make sure you are in the project source directory.
Do a composer install.
$ composer install
Run the tests.
$ vendor/bin/phpunit
or
$ composer test
Similar projects
License
Copyright (c) Kamal Khan. Released under the MIT License.