Ошибка переменной ветки

I have array in PHP:

    array(
        'name1' => 'one',
        'name2' => 'two',
        'name3' => 'three'
    )
    

but in twig:

    {% for i in range(1, 3) %}
        {{'name' ~ i}}
    {% endfor %}
    

give me:

    1
    2
    3
    

Помогите мне, пожалуйста. Спасибо.


person IamSCORPION    schedule 25.04.2012    source источник


Ответы (1)


Ты можешь это сделать:

  {% for i in range(1, 3) %}
        {{ attribute(_context, 'name' ~ i) }}
  {% endfor %}

Иметь:

one
two
three
person Antoine REYT    schedule 25.04.2012