stratify / twig-module
Stratify 的 Twig 模块
0.3.1
2018-02-03 21:39 UTC
Requires
- php-di/php-di: ^6.0.0-alpha4
- stratify/router: ~0.6.0
- twig/twig: ^1.21
Requires (Dev)
- phpunit/phpunit: ^6.0
README
为 Twig 与 Stratify 一起工作进行的预配置。
安装
composer require stratify/twig-module
然后在 Stratify 应用程序中启用 stratify/twig-module
模块。
用法
Twig_Environment
实例现在可以在任何依赖注入可用的地方注入。
Stratify 控制器的示例
function (Twig_Environment $twig) { return $twig->render('home.twig'); }
配置
如果需要,可以自定义以下配置选项
-
twig.paths
:包含要注册的模板的路径'twig.paths' => add([ __DIR__.'/../views', ]),
然后可以将模板渲染为
foo.twig
。模板也可以有命名空间,这对于可重用的模块可能很有用
'twig.paths' => add([ 'blog' => __DIR__.'/../views', ]),
然后可以将模板渲染为
@blog/foo.twig
。 -
twig.options
:有关 Twig 选项 的更多信息'twig.options' => add([ 'strict_variables' => true, ]),
-
twig.globals
:有关 全局变量 的更多信息,这些变量在模板中可用'twig.globals' => add([ 'appName' => 'My super project', 'debug' => get('debug'), // container parameters can be injected too ]),
-
twig.extensions
:一组 Twig 扩展'twig.extensions' => add([ get(Twig_Extension_Profiler::class), get(My\Custom\TwigExtension::class), ]),
生产 推荐的选项
'twig.options' => [ 'cache' => /* cache directory */, ],
开发 推荐的选项
'twig.options' => [ 'debug' => true, 'cache' => false, 'strict_variables' => true, ],