Tracy Twig extensions (docs)
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
<?php
$loader = new Twig_Loader_Filesystem(__DIR__);
$twig = new Twig_Environment($loader, ['debug' => true]);
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));
{% 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