americanreading/view-twig
最新稳定版本:v2.1.0
Composer 安装命令:
composer require americanreading/view-twig
包简介
Twig Implementation of Views
README 文档
README
Twig-backed implementation of View and ViewFactory.
To use, include with Composer:
{
"require": {
"americanreading/view-twig": "^1",
"twig/twig": "^2"
}
}
Configure a Twig_Environment and pass this to the TwigView constructor along with the root path to the view templates.
$templateRoot = '/path/to/twig/template/files';
$loader = new \Twig_Loader_Filesystem($templateRoot);
$conf = [
'debug' => true,
'cache' => false,
'autoescape' => false
];
$twig = new \Twig_Environment($loader, $conf);
// Provide a context array to use as a default for all views.
$defaultContext = [
'cat' => 'Molly'
];
// Create the factory.
$factory = new TwigViewFactory($twig, $templateRoot, $defaultContext);
Use the factory to provide View instances for a given template file:
$view = $factory->getView('my-template.twig.html');
Render the view to a string, merging in a context array.
$html = $view->render(['dog' => 'Bear']);
统计信息
- 总下载量: 8.38k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-05-22