get current url in twig template?

后端 未结 6 1358
粉色の甜心
粉色の甜心 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条回答
  •  隐瞒了意图╮
    2020-11-30 18:17

    {{ path(app.request.attributes.get('_route'),
         app.request.attributes.get('_route_params')) }}
    

    If you want to read it into a view variable:

    {% set currentPath = path(app.request.attributes.get('_route'),
                           app.request.attributes.get('_route_params')) %}
    

    The app global view variable contains all sorts of useful shortcuts, such as app.session and app.security.token.user, that reference the services you might use in a controller.

提交回复
热议问题