Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

Examples below are useful tips for us to benefit from in twig templates.


Print namespace and current method


{{ app.request.attributes.get("_controller") }}

# Output
Football\FrontendBundle\Controller\DefaultController::indexAction

Print router name


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

# Output
football_frontend_homepage

Print router parameters


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

# Output - Assuming that the URI is http://sport.local/app_dev.php/inanzzz
array:1 [
"name" => "inanzzz"
]

Print query string parameters


# URL
app_test.php/emails?type=delivered&from_date=26-02-2015&to_date=26-02-2016&limit=25&keyword=

{{ dump(app.request.query.all) }}

# Output
array:5 [
"type" => "delivered"
"from_date" => "26-02-2015"
"to_date" => "26-02-2016"
"limit" => "25"
"keyword" => ""
]