如何在app.request中添加一个新参数


How to add a new parameter in the app.request from twig

我想在app.request from twig中添加一个新参数。

我已经尝试过了,但没有得到我预期的结果:

{% set app.request.query.set('script') = false %}

你应该永远不要改变Twig模板中的请求对象。我认为这根本不可能。

如果你只是想添加一个参数,并在当前模板中使用它,只需这样做:

{% set parameters = app.request.query.all()|merge({'script': false}) %}