xy2z / blader
A lightweight template router
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 0
Language:HTML
Type:project
Requires
- xy2z/blader-core: ^1.1
This package is auto-updated.
Last update: 2020-08-17 11:58:47 UTC
README
A lightweight template router - for websites with no/minimal dynamic needs.
Using BladeOne - a standalone version of Laravel's blade template engine.
Install
composer create-project xy2z/blader mysite
cd mysite/public
php -S 127.0.0.1:81
Go to http://127.0.0.1:81
Requirements
- PHP 7.0 or above.
Basic Usage
require '../vendor/xy2z/blader-core/src/init.php'; $blader->addRoute('GET', '/', 'home'); // Renders '../views/home.blade.php' $blader->addRoute('GET', '/about', 'about'); // Renders '../views/about.blade.php' $blader->not_found_view = '404'; // Renders '../views/404.blade.php' on 404. $blader->render();
That's it.
Features
Global variables
In your /public/index.php
, add:
$blader->global_vars = [ 'foo' => 'bar', ];
Config
A default config file is added in config/app.php
. You can delete this if you don't need it.
You can add as many files here as you want. PHP
, INI
and JSON
files are supported.
You can access the config everywhere by calling Config::get('filename.key')
.
Use Config::get('app.name')
to access the name
key in config/app.php
:
Route specific headers
$blader->addRoute('GET', '/rss', 'rss', function() { header('Content-type: application/rss+xml; charset=utf-8'); });
Adding route specific variables
$blader->addRoute('GET', '/rss', 'rss', function() { // Return all variables you want in the view. return [ 'foo' => 'bar', ]; }); // 'views/rss.blade.php' can now print $foo