Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 312 Vote(s) - 3.47 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Access Route Parameters in twig Template

#1
How can I access route parameters in a twig template without knowing the name of the parameter/s ?
Reply

#2
You can get all route parameters with:

{{ app.request.attributes.get('_route_params') }}

if you want just one parameter:

{{ app.request.attributes.get('_route_params')['YOUR_PARAMETER_KEY'] }}
Reply

#3
if you want to use the current route with its parameter as a url:
>{{ path(app.request.get('_route'),app.request.get('_route_params')) }}

This can be helpful when you want to eliminate any concatenated strings from the url.

app.request.get('_route') gives you the route name from request bag.
app.request.get('_route_params') gives you the route parameters
{{ path(route_name, array of parameters) }} create the path
Reply

#4
Route parameters can be accessed in the following way in Twig:

{{ app.request.attributes }}

You can also use the [`dump()`](

[To see links please register here]

) function to see what methods are available:

<pre>
{{ dump(app.request.attributes) }}
</pre>

Here's a dump of all the parameters:

**Requesting URL**

[To see links please register here]


Route = test
Slug = {param1} = 3

**Twig Code**

{{ dump(app.request.attributes) }}

**Returns**

object(Symfony\Component\HttpFoundation\ParameterBag)[10]
protected 'parameters' =>
array (size=3)
'_controller' => string 'MyTest\Bundle\Controller\TestController::indexAction' (length=61)
'param1' => string '3' (length=1)
'_route' => string 'test' (length=7)

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through