Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twig get url parameter with []

Tags:

php

twig

symfony

I have an url like : MYURL?filter[_per_page]=25&filter[name][value]=hello

How can i get these parameters with twig ?

I'm trying {{ app.request.get('filter[_per_page]') }} but it's always empty...

Thanks !

Edit : I'm in javascript an i want to assign this result to a javascript variable like : var param = "{{ app.request.get('filter[_per_page]') }}";

like image 263
Clément Andraud Avatar asked Feb 11 '15 14:02

Clément Andraud


People also ask

How do I get the current URL in twig?

You can get the current URL in Twig/Silex 2 like this: global. request. attributes. get('_route') .


1 Answers

You must manage as an array accessing to the filter element as:

{{ app.request.get('filter')['_per_page'] }}

(This time I try before posting...)

like image 186
Matteo Avatar answered Oct 17 '22 04:10

Matteo