Urlize and trailing slash

Just wondering why is there no trailing slash when you use the urlize function?

From the docs:

tags = ["pizza","beer","hot dogs"]

{{range .}}
  <a href="/tags/{{ . | urlize }}">{{ . }}</a>
{{end}}

<a href="/tags/pizza">pizza</a>
<a href="/tags/beer">beer</a>
<a href="/tags/hot-dogs">hot dogs</a>

If I’d like a trailing slash, what should I do? Just add add a slash like so:

<a href="/tags/{{ . | urlize }}/">{{ . }}</a>

I think so. At least I don’t know of a better way to do this.

For better readability, I used print to build the URL.

1 Like