yep/tracy-twig-extensions

Twig extensions for Tracy Debugger

v1.1.1 2017-03-10 23:41 UTC

This package is auto-updated.

Last update: 2024-10-11 18:56:36 UTC


README

Build Status Scrutinizer Code Quality Scrutinizer Code Coverage Latest Stable Version Total Downloads License

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