user2143356
user2143356

Reputation: 5597

Twig Symfony2 get Request variable

I know I can do this:

app.request.get('name')

...but how do I do this?

app.request.get(twig_var_name)

I've tried every obvious solution {{}} () etc.

Is it possible?

Upvotes: 37

Views: 75207

Answers (2)

xarlymg89
xarlymg89

Reputation: 2617

This isn't a problem nowadays (Symfony 4.4 and 5 at least).

I've tried getting a request parameter using this:

{% set getParamName = 'sort' %}
<input type="hidden" name="sort" value="{{ app.request.get(getParamName) }}" />

And there were no issues at all. It works perfectly fine.

Upvotes: 0

S.Thiongane
S.Thiongane

Reputation: 6905

have you tried :

app.request.get('' ~ twig_var_name)

Upvotes: 61

Related Questions