0

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.

CarlosAS
  • 654
  • 2
  • 10
  • 31
  • Possible duplicate: http://stackoverflow.com/questions/6787895/how-to-get-config-parameters-in-symfony2-twig-templates – akluth Nov 28 '13 at 13:36

1 Answers1

1

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.

Nicolai Fröhlich
  • 51,330
  • 11
  • 126
  • 130