symfonytwigtwig-extension

How to use an environment variable (from `.env` file) in custom Twig function in Symfony?


How can I use an environment variable from the .env file in a custom Twig function (\Twig_SimpleFunction) in Symfony 4?


Solution

  • It's possible to access env vars in a twig template without any additional configuration:

    {{ app.request.server.get('MY_ENV_VAR') }}