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.

1

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.