Twig extension for dumping a variable in NiceDump format

v1.1.0 2021-08-19 13:07 UTC

This package is auto-updated.

Last update: 2022-01-19 14:03:29 UTC


Tests StyleCI License Latest Stable Version Total Downloads

Twig extension to dump a variable according to the NiceDump format specification.


  • PHP >= 7.3

Install with composer

$ composer require nicedump/nicedump-twig

Basic usage

After enabling this extension, the nice_dump() function can be used in Twig templates to output a variable in NiceDump format.

The variable is only output if debug mode is enabled in Twig, otherwise nice_dump() returns just an empty string. This makes it possible to use the function both in development and production mode.

Dump a variable

{{ nice_dump(foo) }}

This may output something like this:

=====END NICE-DUMP=====

Notice that the NiceDump in enclosed in an HTML comment.

Dump a variable with a name

{{ nice_dump(foo, 'Foo') }}

Dump a variable with a name and a comment

{{ nice_dump(foo, 'Foo', 'This is my Foo') }}

Enable output in release mode

Caution: This may unintentionally reveal secret data on a production server. Use with care!

Enable nice_dump() to output a NiceDump, even when Twig is in non-debug mode:

use NiceDumpTwig\NiceDumpTwigExtension;

$extension = new NiceDumpTwigExtension();