bnf/pug-view
Composer 安装命令:
composer require bnf/pug-view
包简介
Render PUG templates into a PSR-7 Response object.
README 文档
README
PUG Renderer
This is a renderer for rendering PUG templates into a PSR-7 Response object. It works well with Slim Framework 3.
Installation
Install with Composer:
composer require bnf/pug-view
Usage with Slim 3
use Bnf\PugView\PugRenderer; include 'vendor/autoload.php'; $app = new Slim\App(); $container = $app->getContainer(); $settings = [ 'extension' => '.pug', 'basedir' => 'templates/' ]; $container['view'] = function($c) { return new PugRenderer($settings); }; /* PugRenderer is added as middleware to automatically inject the $response object. */ $app->add('view'); /* Add global template variables */ $app->add(function($request, $response, $next) { $this->view->set('title', 'default title'); // Make the container accessible in the view, so that every object can be accessed in the template: // E.g: a(href=c.router.pathFor('named-route')) $this->view->set('c', $this); return $next($request, $response); }); $app->get('/hello/{name}', function ($request, $response, $args) { return $this->view->render('hello', $args); }); $app->run();
Usage with any PSR-7 Project
//Construct the View $settings = [ 'extension' => '.pug', 'basedir' => 'templates/' ]; $phpView = new PugRenderer($settings); //Render a Template $response = $phpView->render('template', $yourData, new Response());
统计信息
- 总下载量: 53
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-04-22