Wallogit.com
2017 © Pedro Peláez
Super small view engine for those that want to play it safe.
This is FlipFlop. A super, super tiny view engine that is used by BIRD3 to display things in it's new Laravel core., (*1)
I made this since I just wanted to run regular PHP templates without anything super fancy. So I just made this!, (*2)
__partial__ variable, or by using the FlipFlop facade.$this.PhpEngine, meaning that we are 100% API compatible.Your typical, (*3)
composer require ingwiephoenix/bird3-flipflop
will work just fine., (*4)
Next, you'll want to pop config/app.php and look for, (*5)
Illuminate\View\ViewServiceProvider::class,
... and add this underneath:, (*6)
BIRD3\Extensions\FlipFlop\Providers\FlipFlopServiceProfider::class,
... and within the alias section, you'd add:, (*7)
"FlipFlop" => BIRD3\Extensions\FlipFlop\Facades\FlipFlop::class,
.. and it's done!, (*8)
<?php
// While bootstrapping...
// By default: app_path("Resources/Views/Layouts")
// But you can always append another path.
View::addLocation(app_path("Resources/theme"));
// Or add modules and such as "namespace". Note, the two are idendical.
View::addNamespace("Derp", app_path("Derp/Views"));
// When sending back a response...
Route::get("/", function(){
return View::make("Derp::index");
});
Route::get("/bad-guy", function(){
$view = View::make("Herp::showcase");
return $view->with(["foo"=>42]);
});
// Use a custom context.
Route::get("/customer", function(){
// Using traditional View API:
$view = View::make("Customer::main");
$view->getEngine()->setContext(Auth::user());
// Via facade
$view = FlipFlop::loadWithContext("Customer::main", Auth::user());
return $view;
});
You usually want to define your layout just like any other template. Say you put it into app/Resources/Views/Layouts/main.php, then you would be able to go right ahead, since this is the default that FlipFlop will look for. To change that:, (*9)
FlipFlop::setDefaultLayout($viewName)
Just like views, layouts are resolved the same way., (*10)
You get the content of the view via the $contents variable - but you are free to use the features provided by the View facade as well. If you didn't know, check out what it can actually do., (*11)