nicedump / nicedump-twig
Twig extension for dumping a variable in NiceDump format
Installs: 2 692
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: >=8.0
- nicedump/nicedump: ^2.0
- twig/twig: ^2.4||^3.0
Requires (Dev)
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-10-01 11:56:48 UTC
README
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