Twig - Get URL for Canonical Tag

I want to create a dynamic rel = "canonical" tag in my application that pulls out the current url but wants all request parameters to be removed. For example, http://www.example.com/test/?page=2 must have the canonical symbol http://www.example.com/test/ , so {{ app.request.uri }} doesn’t work like this either pulls ?page=2 .

Does anyone know how to pull the absolute path of a page without query parameters?

+7
symfony twig canonical-link
source share
2 answers

It will work

 {{ url(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')) }} 
+9
source share

I just tried resetting baseUrl and confirming that it is not working.

However, this one works :

 {{ app.request.getSchemeAndHttpHost ~ app.request.baseUrl ~ app.request.pathInfo }} 

I know this is not very, but it does the job :)

+5
source share

All Articles