I’ve recently started developing a web application in Laravel using the Twig templating engine and I ran into a problem trying to get the full page url as a variable in the template.

I tried a whole heap of different options including those suggested in a Google search but they either didn’t work or looked way more complicated than they should have.

For reference, neither {{ app.request.getRequestURI() }} and {{ app.request.getUri() }} worked for me when I tried to get the full url in a Laravel Twig template.

If you’re trying to get the full site url in Laravel + Twig, try using these two options:

{{ url_current() }}

This tag calls URL::current() and displays the current url without any url parameters.

Eg: korske.com/post.php?id=123 will be displayed without the ?id=123 paramaters.

{{ url_full() }}

This tag calls on URL:full()  and will display the whole url including all additional parameters.

Using the same example as above, it will show the whole address as it is in the address bar.

This worked on Laravel 4.2 running Twig 1.15.1 and Rob Crowe’s Twigbrige 0.5.3.