如何在树枝模板中设置数组值 [英] How to set array value in twig template

查看:12
本文介绍了如何在树枝模板中设置数组值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何通过 twig 模板中的字符串索引更改数组值?我正在尝试:

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

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

但我收到 nex 错误:

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

我也在尝试:

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

但也有错误:

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

有什么想法吗?

推荐答案

怎么样,

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

这篇关于如何在树枝模板中设置数组值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆