clickcoder / slim-blade by clickcoder

Blade is a simple, yet powerful templating engine provided for the Slim Framework
4,614
32
3
Package Data
Maintainer Username: clickcoder
Maintainer Contact: kevin@kevindarren.com (clickcoder)
Package Create Date: 2014-07-21
Package Last Update: 2014-07-22
Language: PHP
License: MIT
Last Refreshed: 2024-04-23 03:02:38
Package Statistics
Total Downloads: 4,614
Monthly Downloads: 0
Daily Downloads: 0
Total Stars: 32
Total Watchers: 3
Total Forks: 10
Total Open Issues: 6

slim-blade

Blade is the default template engine of Laravel. The main advantage of Blade is template inheritance whilst using plain PHP. This package allows you to use Blade within the Slim Framework.

How to Install

using Composer

The package can be installed via Composer by requiring the "clickcoder/slim-blade": "dev-master" package in your project's composer.json.

{
    "require": {
        "clickcoder/slim-blade": "dev-master"
    }
}

Then run the following composer command:

$ php composer.phar install

Blade

How to use

<?php
require 'vendor/autoload.php';

$app = new \Slim\Slim(array(
    'view' => new \Slim\Views\Blade(),
	'templates.path' => './templates',
));

To use Blade cache do the following:

$view = $app->view();
$view->parserOptions = array(
    'debug' => true,
    'cache' => dirname(__FILE__) . '/cache'
);

You can use all blade features as described in the Laravel 4 documentation: http://laravel.com/docs/templates#blade-templating

Example

Create the following index.php file

<?php
require 'vendor/autoload.php';

$app = new \Slim\Slim(array(
    'view' => new \Slim\Views\Blade(),
	'templates.path' => './templates',
));

$view = $app->view();
$view->parserOptions = array(
    'debug' => true,
    'cache' => dirname(__FILE__) . '/cache'
);

$app->get('/hello/:name', function ($name) use ($app) {
	$app->render('master', array(
		'variable' =>  "Hello, $name"
	));
});

$app->run();

Create a templates folder and add this inside

<!DOCTYPE html>
<html lang="en">
    <body>
		{{ $variable }}
    </body>
</html>

visit /index.php/hello/world

Authors

Kevin Darren

License

MIT Public License