Download the PHP package patrick-maynard/twig-stack-trace-dumper without Composer
On this page you can find all versions of the php package patrick-maynard/twig-stack-trace-dumper. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download patrick-maynard/twig-stack-trace-dumper
More information about patrick-maynard/twig-stack-trace-dumper
Files in patrick-maynard/twig-stack-trace-dumper
Package twig-stack-trace-dumper
Short Description A Twig extension that allows the user to get a stack trace from within a template
License MIT
Homepage http://home.patrickmaynard.com
Informations about the package twig-stack-trace-dumper
Stack Trace Dumper Twig Extension
This Twig extension adds the trace() function to Twig.
It will output a string containing a stack trace.
I recommend only using it as a dev dependency. Using it in a production environment is probably not a good idea.
I created this tool for use in an environment where neither the Symfony toolbar nor XDebug was available.
Assuming you are able to use those better tools, I would urge you to do so.
Installation
To install this tool as a dev dependency:
Configuration and usage
You'll then need to configure your app to have access to the extension.
Assuming you're using Symfony, you can do that using the instructions here: https://symfony.com/doc/current/templating/twig_extension.html#register-an-extension-as-a-service
Once that's done, you can use the new function in Twig files like this:
UPDATE: As of 2025, the Symfony documentation is pretty flippant about what you need to do to register your extension, essentially saying that it will be registered via magic. This is not always reliable, so you may or may not need to add something like the following to your services.yaml
file:
If you want a little more detail than {{ trace()|raw }}
provides, you could also try using {{ trace_via_debug_backtrace()|raw }}
to get different formatting and some extra information. I have only done a smoke test on this. If you get a chance to write an integration test for this function, please open a pull request. Thank you.
Happy debugging!