Is there any facility to generate a path for a given route and arguments, appending the query string automatically? As a temporary workaround i'm using a self made macro:
{% macro path(route, args, with_query) %}
{% spaceless %}
{% set with_query = with_query|default(false) and app.request.queryString %}
{{ path(route, args) ~ (with_query ? '?' ~ app.request.queryString : '' ) }}
{% endspaceless %}
{% endmacro %}
Is there some native function in Symfony2/Twig for doing this?
A nice thing with path Twig extension is that unknow parameters passed through the args array are automatically appended at the end of the URL as GET paramaters :
{{ path('route_id', {'routeParam':'foo', 'unknownParam':'bar'}) }}
will produce
/path/to/route/foo?unknownParam=bar
As simple as :
{{ path('route_id', app.request.query.all) }}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With