nicedump/nicedump-twig

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: 2021-10-19 13:29:52 UTC


README

Tests StyleCI License Latest Stable Version Total Downloads

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

Requirements

  • 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:

<!--
=====BEGIN NICE-DUMP=====
eyJ0eXBlIjoic3RyaW5nIiwidmFsdWUiOiJGb28iLCJzaXplIjozfQ==
=====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();
$extension->enableInReleaseMode();

License

MIT