Replies: 9 comments 4 replies
-
Can you confirm that the templates are compiled without symfony/debug-bundle installed? |
Beta Was this translation helpful? Give feedback.
-
How can I tell that? composer.json: "require-dev": {
"symfony/debug-bundle": "^7.2", bundles.php return [
Symfony\Bundle\DebugBundle\DebugBundle::class => ['dev' => true],
Symfony\Bundle\TwigBundle\TwigBundle::class => ['all' => true],
Symfony\Bundle\FrameworkBundle\FrameworkBundle::class => ['all' => true],
Doctrine\Bundle\DoctrineBundle\DoctrineBundle::class => ['all' => true],
Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle::class => ['all' => true],
Symfony\Bundle\WebProfilerBundle\WebProfilerBundle::class => ['dev' => true, 'test' => true],
Symfony\UX\StimulusBundle\StimulusBundle::class => ['all' => true],
Symfony\UX\Turbo\TurboBundle::class => ['all' => true],
Twig\Extra\TwigExtraBundle\TwigExtraBundle::class => ['all' => true],
Symfony\Bundle\SecurityBundle\SecurityBundle::class => ['all' => true], |
Beta Was this translation helpful? Give feedback.
-
So, the bundle is available during template compilation, so the compiled template contains the |
Beta Was this translation helpful? Give feedback.
-
Should I be doing something differently? My idea was do avoid inadvertently allowing a dump() call in production, which has burned me, especially when I do something like {{ app.request.get('debug') ? dump(article) }} I thought the better way to do it would be {% guard function dump %}
{{ app.request.get('debug') ? dump(article) }}
{% endguard %} Am I misunderstanding something about |
Beta Was this translation helpful? Give feedback.
-
The |
Beta Was this translation helpful? Give feedback.
-
I always assumed that happened during |
Beta Was this translation helpful? Give feedback.
-
That should work then but again only if you have dev deps installed, which doesn’t seem to be the case. |
Beta Was this translation helpful? Give feedback.
-
Create a new symfony app: symfony new ignore-dump-in-production --webapp && cd ignore-dump-in-production
bin/console make:controller AppController
sed -i "s|/app|/|" src/Controller/AppController.php
cat <<'EOF' > templates/app/index.html.twig
{% extends 'base.html.twig' %}
{% block body %}
{% guard function dump %}
{{ dump() }}
{% else %}
dump cannot be used in production
{% endguard %}
{% endblock %}
EOF
symfony server:start -d
symfony open:local Now run in production
Logs show [Web Server ] Jan 3 05:17:23 |ERROR | SERVER GET (500) / ip="127.0.0.1" |
Beta Was this translation helpful? Give feedback.
-
This feature would be really cool, to have dump() available only in dev and not break prod. I keep getting burned by leaving dumps in production, where they throw an error just being there, even if surrounded by an if statement so they're not exposed. Is this something that might be fixed in twig 4? |
Beta Was this translation helpful? Give feedback.
-
I use this to make sure dumps don't happen in production. symfony/debug-bundle is not installed on production, symfony/twig-bundle is. Everything's updated to the latest code
When I run it in production, it fails, I see this message in the logs:
Of course, symfony/twig-bundle is installed. And this works fine in dev. And I think this used to work before the latest 7.2.2.
Beta Was this translation helpful? Give feedback.
All reactions