clickcoder/slim-blade

Blade 是为 Slim 框架提供的简单但强大的模板引擎

dev-master 2014-07-22 19:36 UTC

This package is not auto-updated.

Last update: 2024-09-24 03:17:48 UTC


README

Blade 是 Laravel 的默认模板引擎。Blade 的主要优势是使用纯 PHP 进行模板继承。此包允许你在 Slim 框架中使用 Blade。

如何安装

使用 Composer

您可以通过在项目的 composer.json 中要求 "clickcoder/slim-blade": "dev-master" 包来通过 Composer 安装此包。

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

然后运行以下 composer 命令

$ php composer.phar install

Blade

如何使用

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

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

要使用 Blade 缓存,请执行以下操作

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

您可以使用 Laravel 4 文档中描述的所有 Blade 功能:https://laravel.net.cn/docs/templates#blade-templating

示例

创建以下 index.php 文件

<?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();

创建一个 templates 文件夹,并在其中添加以下内容

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

访问 /index.php/hello/world

作者

Kevin Darren

许可证

MIT 公共许可证