How to set array value in twig template

2019-02-25 02:43发布

问题:

How I can change my array value by string index in twig template? I'm trying:

{% do params['redirect_uri'] = 'http://site.loc/' %}

but I get nex error:

Unexpected token "operator" of value "=" ("end of statement block" expected) in
BWUserBundle:User/social:sign-in-thumbs.html.twig at line 4

I also trying:

{% set params['redirect_uri'] = 'http://site.loc/' %}

but have error too:

Unexpected token "punctuation" of value "[" ("end of statement block" expected) in 
BWUserBundle:User/social:sign-in-thumbs.html.twig at line 4

Any ideas?

回答1:

what about,

{% set params = params|merge({'redirect_uri': 'http://site.loc/'}) %}