yep / tracy-twig-extensions
Tracy Debugger 的 Twig 扩展
v1.1.1
2017-03-10 23:41 UTC
Requires
- php: >=5.6.0
- tracy/tracy: ^2.4
- twig/twig: ^1.31|^2.0
Requires (Dev)
- phpunit/phpunit: 5.4.*
- yep/reflection: ^1.0
README
Tracy Twig 扩展(文档)
Tracy Twig 扩展
Tracy Twig 扩展可在 Packagist.org 上找到,只需将依赖项添加到您的 composer.json 文件中。
{ "require" : { "yep/tracy-twig-extensions": "^1.0" } }
或运行 Composer 命令
php composer.phar require yep/tracy-twig-extensions
用法
首先,您必须启用 Twig 环境中的调试。
<?php $loader = new Twig_Loader_Filesystem(__DIR__); $twig = new Twig_Environment($loader, ['debug' => true]);
其次,您必须将扩展添加到 Twig 环境中。
用于 \Tracy\Dumper::dump
<?php use Yep\TracyTwigExtensions\DumpExtension; $twig->addExtension(new DumpExtension()); // If you want to see dump in colors, you must enable Tracy\Debugger // use Tracy\Debugger; // Debugger::enable(Debugger::DEVELOPMENT); // You can specify dump options $options = [ Tracy\Dumper::DEPTH => 5, Tracy\Dumper::TRUNCATE => 500 ]; $twig->addExtension(new DumpExtension($options));
用于 \Tracy\Debugger::barDump
<?php use Yep\TracyTwigExtensions\BarDumpExtension; use Tracy\Debugger; Debugger::enable(Debugger::DEVELOPMENT); $twig->addExtension(new BarDumpExtension()); // You can specify dump options $options = [ Tracy\Dumper::DEPTH => 5, Tracy\Dumper::TRUNCATE => 500 ]; $twig->addExtension(new BarDumpExtension($options));
在模板中使用
{% for i in 1..3 %} {{ dump(i) }} // dump single variable {% endfor %} {{ dump(variable,'bar') }} // dump multiple variables {{ dump() }} // dump all variables from the current context
或
{% for i in 1..3 %} {{ barDump(i) }} // dump single variable {% endfor %} {{ barDump(variable,'bar') }} // dump multiple variables {{ barDump() }} // dump all variables from the current context