Generate Section URLs


I’m currently building It is the help site for

My content organization is pretty basic. I hope I’ll get the wording right because for a beginner Hugo is pretty confusing.

|-- About\ spolytics
|   `-- How\ much\ does\ spolytics\ cost?.md
|-- How\ do\ I\ use\ the\ app?
|   |--
|   |--
|   |--
|   |--
|   |--
|   |--
|   |--
|   `--
`-- Understanding\ beach\ volleyball\ analysis
    |-- What\ is\ a\ category?.md
    `-- What\ is\ an\ outcome?.md

Everything is hosted at AWS S3 using this config

baseURL = ""
languageCode = "en-us"
title = "spolytics Help"
theme = "zafta"
pluralizelisttitles = false
uglyURLs = true

Here is the code to generate the breadcrumbs which should link to the individual sections. Each section should show a list of pages which are inside this section.

  <ol class="breadcrumb">
      <a href="/{{ .Section | urlize }}.html">
        {{ .Section }}
    <li class="active">
      {{ .Title }}

As you can see I had to manually include the .html suffix. That means if I remove uglyURLs = true from my config in the future I also have to remove the hardcoded .html ending from my templates. I don’t think this is right.

So here is my question: How do I generate a link to a section from inside a single page?

My goal is to have a help page very similar to Not the first “Common Issues” block but below that one.


Assuming you are asking how to link to a section’s index page (i.e., a list template) from within a single page template, you might find some utility in the .GetPage function.

Thank you for your response. Using

{{ .Site.GetPage "section" }}`

just below my breadcrumbs returns <nil>.

How about…(not tested)…

{{$sec := .Section}}
{{with .Site.GetPage "section" $sec}}{{.Permalink}}{{end}}

Would need to be modified per your templating, but just so you can get an idea of how to use the function, which requires a kind for a first argument and a second argument…

I’m not sure why you need the urglyURLs = true but in my case, I just use the url without “.html” prefix which is the “pretty” url, and just link it using "/{{ .Section | urlize }}". This makes life much easier.

Looks nice! Will try tonight! Thank you.


{{ .Site.GetPage "section" .Section }}

but that didn’t work.

Will report if this solves the problem.

I need urglyURLs = true because the page is hosted on Amazon S3. You cannot use pretty URLs over there execept for the main page, i.e. index.html.

You can also use pretty URLs with S3, I do that with my Hugo websites on S3 too. S3 is smart enough to, when requesting, to fetch the file.

It’s a bit offtopic, but just saying in case you’d rather use pretty URLs. :slightly_smiling:

I’m not sure if I follow this question, because I don’t see a problem. In Hugo, we only have a top-most section (see this doc page, for example).

Because .Section returns the section of the current page, and because there’s only one possible section for each content (or no section at all), I think this will always generate a link to your section page (it does in my case, at least):

{{ .Site.BaseURL }}/{{ .Section }}/

Or, if you’re using ugly URLs:

{{ .Site.BaseURL }}/{{ .Section }}.html

I don’t see the need to complicate matters with the .GetPage function, since you’re only looking to generate a URL to the current section, right?

Hope my 2 cents help.

I’m pretty sure you can have pretty URLs with S3.

Here’s a link to the blog post on our website: (Sorry it’s in Vietnamese but you get the idea)

It’s hosted on S3 and it has pretty URLs for blog posts.

If you have any problem with having pretty URLs on S3, we’re happy to help.

I would steer clear of any construction that uses BaseURL to create your URLs. Try relURL or absURL instead.

Can you say why?

Tends to be more fragile…and until recently, usage was pretty inconsistent, especially in themes. {{ "whatever-string" | absURL }} is more consistent. See this comment in a related issue:

1 Like

Better late than never. That didn’t work. The result was simply blank.

@zemirco Can you point me to a repo for this project so I can test locally? Also, what version of Hugo are you using?

Here is a repo you can play with