This library provides methods to use environment variables in Twig templates.
composer require oskarstark/env-var-extension
# config/services.yaml
services:
OskarStark\Twig\EnvVarExtension:
tags: ['twig.extension']
To access the value of an existing environment variable BRANCH_NAME=develop
{{ env(BRANCH_NAME) }} # prints 'develop'
You can also check if an envirnment variable exists:
{{ has_env(BRANCH_NAME) }} # returns: true