hugo/docs/content/en/functions/urls/URLize.md
2023-10-20 09:43:56 +02:00

1.6 KiB

title linkTitle description categories keywords menu function relatedFunctions aliases
urls.URLize urlize Takes a string, sanitizes it for usage in URLs, and converts spaces to hyphens.
functions
docs
parent
functions
aliases returnType signatures
urlize
string
urls.URLize INPUT
urls.Anchorize
urls.URLize
/functions/urlize

The following examples pull from a content file with the following front matter:

{{< code-toggle file="content/blog/greatest-city.md" fm=true copy=false >}} title = "The World's Greatest City" location = "Chicago IL" tags = ["pizza","beer","hot dogs"] {{< /code-toggle >}}

The following might be used as a partial within a single page template:

{{< code file="layouts/partials/content-header.html" >}}

{{ .Title }}

{{ with .Params.location }}
{{ . }}
{{ end }} {{ with .Params.tags }}
    {{ range .}}
  • {{ . }}
  • {{ end }}
{{ end }} {{< /code >}}

The preceding partial would then output to the rendered page as follows:

<header>
  <h1>The World&#39;s Greatest City</h1>
  <div><a href="/locations/chicago-il">Chicago IL</a></div>
  <ul>
    <li>
      <a href="/tags/pizza">pizza</a>
    </li>
    <li>
      <a href="/tags/beer">beer</a>
    </li>
    <li>
      <a href="/tags/hot-dogs">hot dogs</a>
    </li>
  </ul>
</header>