I know you can set global variables in TWIG this way :
# config.yml
# Twig Configuration
twig:
debug: "%kernel.debug%"
strict_variables: "%kernel.debug%"
cache : false
globals :
server : 127.0.0.1
Now what I want is to create a custom variable server
that uses the preexistent global variable app.request.host
. I can reference that variable in a TWIG template, but how can I do that in a YML file ?
In one sentence : I want to create a global TWIG variable from another one.
Why don't you go with a parameter. Just put it in you parameters.yml
server: 127.0.0.1
after that you can refer to it in yml files like this:
"%server%"
add it to globals like this:
twig:
globals:
server: '%server%'
if you need it in controller, then use this approach:
$this->getParameter("server")