arsengoian / viper-blade
A package enabling the use of Blade templating engine in PHP
dev-master
2020-01-02 23:55 UTC
Requires
- php: >=7.1.0
- arsengoian/viper-framework: >=0.2
- philo/laravel-blade: >=3.1
This package is auto-updated.
Last update: 2025-03-01 00:17:42 UTC
README
A Blade templating language adaptation for the Viper Framework
For Blade doc, refer to the official Laravel documentation on Blade
Usage
May be used from the controller like this:
namespace App\Controllers; use Viper\Core\Routing\Controller; use Viper\Core\Routing\Methods\GET; use Viper\Core\Viewable; use Blade\View; use App\Models\Client; class HomeController extends Controller implements GET { public function get (...$args): ?Viewable { $clients = Client::all(); return new BladeView('test', [ 'folks' => $clients, ]); } }
Exception reporting
Exceptions may be parsed nicely in a custom view.
By default, the error.blade.php
is invoked with $e
variable for exception
use \Blade\View::bindErrorView()
for configuration
Setup
Extra variables and error preferences may be passed from a filter (official doc on filters):
namespace App\Filters; use Blade\View; use Viper\Core\Filter; class BladeFilter extends Filter { public function proceed () { // Set up custom error reporting if (!Config::get('DEBUG')) View::bindErrorView('publicErrorView', 'exception'); // These variables will be visible in all the views View::propagateVars([ 'myCustomVar' => 42, 'clientHandler' => Config::get('Clients.HANDLER'), ]); } }