Skip to main content

Parse a URL in Hugo

Published: 2019-01-25 • Lastmod: 2019-09-12

Need to parse a URL in your Hugo templates? Thanks to the urls.Parse function, you don’t have to do a bunch of string manipulation. Here’s a quick example.

We’ll start with this code:

{{ $url := "" }}
{{ $url = urls.Parse $url }}

The urls.Parse function returns a URL struct, so the value of each struct field would be:

Field Value
$url.Scheme https
$url.Path /make-a-hugo-blog-from-scratch/
$url.Fragment wrap-up