Skip to content
FLAVIO COPES
flaviocopes.com
2026

How to get the current url in Hugo

Learn how to get the current URL in Hugo using the .Page.RelPermalink value, trimming the slashes to get a clean relative path like ebooks or ebooks/php.

~~~
{{ trim .Page.RelPermalink "/"}}

This is the result:

yoursite.com/ebooks -> "ebooks"
yoursite.com/ebooks/php -> "ebooks/php"
Tagged: Hugo ยท All topics
~~~

Related posts about hugo: