I'm using the {{ dump(foo) }}
function in Twig to debug my templates. However, if the template is throwing errors after the dump() function, you will only see Symfony's debugging page informing you of the error. You can obviously comment out the offending lines of code in the Twig template, but is there a way to kill the execution of the template immediately after so that the output of the dump() function is the last thing printed on the screen. Naively I'm thinking of something like {{ dump(foo) }} {{ die() }}
. Any ideas on how you could achieve this?
I don't think you should stop PHP execution inside your twig template (even though this is possible using a custom Twig extension). The result would not be what you'd expect because there is a lot more happening between rendering your template and sending it to the browser. If you simply stop execution all this will not happen any more and I'd suspect that you'll get a simple white page.
Perhaps it's a better approach to dump the variable inside the controller. Doing that will send the dump output to the web profiler toolbar which is available even on symfony's error page.
Oh and well, what about just using a comment ({# ... #}
) to disable the non-working part of your template?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With