0
votes

I would like to search some parameters in my parameters.yml file from a template in twig, depending on a variable. I have tried the following but it didn't work:

parameters.yml

twig:
    globals:
        status:
            0: Paused
            1: Running
            2: Closed

template.html.twig (game.status value can be 1, 2 or 3)

{% set var_status = game.status %}
{% set var_statustext = status.get(var_status) %}
<p>Status: {{ var_statustext }}</p>

Also I would like to access this parameters in the controller. How could I do it? Thanks in advance.

1

1 Answers

1
votes

You're looking for a way to access the value of the the global variable status (type => array) for a given key that is itself stored in another variable game.status (type => integer/string ).

Assuming game.status returns 1 ...

Then you can output Running using:

{{ attribute(status, game.status) }}

The attribute function is what you're looking for.