get current url in twig template?

后端 未结 6 1353
粉色の甜心
粉色の甜心 2020-11-30 17:44

I looked around for the code to get the current path in a Twig template (and not the full URL), i.e. I don\'t want http://www.sitename.com/page, I only need

6条回答
  •  -上瘾入骨i
    2020-11-30 18:20

    If you are using Silex 2 you can not access the Request object anymore.

    You can access the current request attributes this way.

    app.request_stack.currentrequest.attributes.get('_route')
    

    And to generate the full current URL : path(app.request_stack.currentrequest.attributes.get('_route'), app.request_stack.currentrequest.attributes.get('_route_params'))

提交回复
热议问题