lejahmie / slim-mustache-view
Slim 框架的 Mustache 视图包
v2.0
2017-02-15 15:01 UTC
Requires
- mustache/mustache: ^2.11
- psr/http-message: ^1.0
- slim/slim: ^3.0
This package is not auto-updated.
Last update: 2024-09-28 20:44:38 UTC
README
Slim Framework 3+ 的 Mustache 视图包,使用 bobthecow 精美的 PHP 实现 Mustache!;-)
如何安装
使用 Composer
$ composer require lejahmie/slim-mustache-view
如何使用
<?php require 'vendor/autoload.php'; $app = new \Slim\Slim(); $container = $app->getContainer(); $container['view'] = function ($c) { $mustache = new \Slim\Mustache\Mustache( '/templates', // Template path array( 'charset' => 'UTF-8', ), array( 'extension' => '.html' ) ); return $mustache; }; $app->get('/', function (Request $request, Response $response) { // The render method takes the reponse object, // template name and finally some data as an array. $response = $this->view->render($response, "hello", ["foo" => 'bar']); return $response; });
方法
render($templateName, $data)
使用 Slim 的 ResponseInterface 渲染 Mustache 模板;$response->getBody()->write($output);
getRenderedMarkup($templateName, $data)
返回渲染后的 Mustache 模板作为字符串。
setTemplatePath($templatePath)
设置 Mustache 查找模板文件的路径。
setLoaderOptions($loaderOptions)
设置 Mustache 文件系统加载器的选项。见:https://github.com/bobthecow/mustache.php/wiki/Template-Loading
setOptions($options)
设置 Mustache 选项。见:https://github.com/bobthecow/mustache.php/wiki
作者
许可
MIT 许可证 (MIT)
变更日志
1.0.1
- 添加了方法
getRenderedMarkup($templateName, $data),允许获取处理后的标记为原始 HTML 字符串。 - 修复了一些错误。
- 更好的 README,因为你们都读这个对吧?:-D
1.0
- 第一版!