How to debug Shopware6 Document Template Variables

How to debug Shopware6 Document Template Variables

In Shopware6 you can easily view the output of your template variables using the dump() function of Twig.

Unfortunately, this is not an suitable option if you want to view the contents of variables inside of PDF documents. Depending on the type of variable the generation of the PDF will fail because too much memory gets consumed. And sometimes parts of variables get printed to the document, but they will get cropped away by the document borders.

So I came across a very simple solution for this. In case you want to dump the contents of the order variable, for example just use:

{{ order | json_encode(constant('JSON_PRETTY_PRINT')) | replace({',': ", "}) }}

We will pipe the order through the json_encode() function to get a formatted string. Also, we add some space to commas. So the text will not flow out of the document.

Title image: https://pixabay.com/de/illustrations/pdf-dokumentieren-dateien-symbole-1783009/