Cant get full url with params and queries from uri.url

Hi everyone,

I’m trying to create a twig template that has a back button in it, so the user can jump back to the previous overview page. The content is handled by ajax.
In the overview page I’m creating a link/url in twig with a param ‘back’ which holds the current url including params and queries. When I’m on page

e.g. /projects?c=new&p=2

the href of the link to the next page with the button in it becomes:

{% set linkUrl = page.url ~ '/back:' ~ uri.url(false) %}
<a href={{ linkUrl }}>Go to page</a>

Now in the next page I’m creating the back button which gets its href url by

{{ uri.param(back) }}

which was added to the new url.

My problem is that I can’t get the full url including all params and queries inside the overview page. Instead im just getting the url without them. So I can pass the param to the next page but without its queries and params, causing the user to loose his last page or category he was browsing. Using Ajax is not part of the problem, as I get no queries in the url as well, when visiting the page directly.

Can someone please tell me what I’m missing here? Thanks!

You just need to build the URL include the the query parts:

Oh well thats it :smiley: thanks for the quick response! I had to build it with:

{% set url = page.url ~ '?back=' ~ uri.url(false) ~ '?' ~ uri.query %}

I thought uri.url gets the full url including queries and params. The documentation says:

This returns the full URL with or without the host.

(e.g. uri.url(false) = grav/section/category/page/param:foo?query=bar)