yep / tracy-twig-extensions
Twig extensions for Tracy Debugger
Installs: 4 207
Dependents: 1
Suggesters: 1
Security: 0
Stars: 5
Watchers: 2
Forks: 3
Open Issues: 0
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 extensions (docs)
Tracy Twig extensions
Tracy Twig extensions are available on Packagist.org, just add the dependency to your composer.json.
{ "require" : { "yep/tracy-twig-extensions": "^1.0" } }
or run Composer command:
php composer.phar require yep/tracy-twig-extensions
Usage
First, you must enable debug in Twig Environment.
<?php $loader = new Twig_Loader_Filesystem(__DIR__); $twig = new Twig_Environment($loader, ['debug' => true]);
Second, you must add extensions into Twig Environment.
for \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));
for \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));
Third, use in templates
{% 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
or
{% 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