nicedump/nicedump-twig

This package is abandoned and no longer maintained. No replacement package was suggested.

Twig extension for dumping a variable in NiceDump format

v2.0.0 2022-09-29 15:52 UTC

This package is auto-updated.

Last update: 2024-10-01 11:56:48 UTC


README

Tests StyleCI License Latest Stable Version Total Downloads

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

Requirements

  • PHP >= 8.0

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