Special characters in taxonomy name (not in taxonomy term)

I am making a website in Hugo [v0.88.1] and it has 2 languages (en and pt-pt) and 2 sections (blog and projects).
I wanted to use two taxonomies: categories and time (YYYY-MM of publication date). And wanted both to be specific to the blog section (not for projects section) and both taxonomies’ terms and values should show up in the path “/blog/”, like this:

Path to terms in taxonomies “categories” and “time” of blog:

Path to the values in a taxonomy term “categories” and “time” of blog:

Portuguese paths would be similar but preceded by /pt-pt/. Example:

So in the config.yaml I set the following (for simplicity showing only the english version):

   category: "blog/categories"
   time: "blog/time"
   categories: "/blog/categories/:title/"
   time: "/blog/time/:title/"

I set the taxonomies name “blog/categories” and “blog/time” because I noticed that this automatically creates the pages in the correct paths “http://localhost/blog/categories/” and “http://localhost/blog/time/”, respectively.

However, now I am having difficulties in using functions such as:
{{ range .Site.Taxonomies.**blog/categories**.Alphabetical }}

My question is:

  1. Can I use special characters in taxonomy names like the “/” in “blog/categories”?
  2. If so how do I then insert the taxonomy name in functions such as
    {{ range .Site.Taxonomies.blog/categories.Alphabetical }}?
  3. If you do not recommend the use of special characters in taxonomy names (e.g.: “blog/categories”) how do I get Hugo to understand that all terms (i.e. lists terms of taxonomy) and taxonomy pages (i.e. lists values of taxonomy term) should be in a path under blog (i.e. “http://localhost/blog/categories/” and “http://localhost/blog/time/”?

Additional Info

  • I am using translation by filename for multilingual capabilities
  • I am using page bundles

I hope I was clear. I am having difficulties understanding the template structure and lookup order in Hugo, as well as what is the use of having taxonomy singular and plural… Things get weirder if I wished to have distinct taxonomies for two sections separately.

Thank you!


{{ $taxonomy := "blog/categories" }}
{{ range $term, $weightedPages := index .Site.Taxonomies $taxonomy }}
  {{ with site.GetPage (path.Join $taxonomy $term) }}
    <h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
  {{ end }}
  {{ range $weightedPages }}
    <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a><br>
  {{ end }}
{{ end }}

Uau thank you very very much!!!
And is it possible to ORDER the taxonomy terms such as Alphabetical with such code (I forgot to mention this in my first post)?

I would still appreciate some kind of explanation as to why a taxonomy name such as “blog/categories” gets immediately mapped to url: …/blog/categories/ and /blog/categories/value/. It seems to be handy because then I dont need to create templates for every single taxonomy-section-language triad…
This must have some kind of impact as to how the files are built in the public directory.

I’m not sure that the ability to namespace taxonomies (e.g., “type/taxonomy”) was a design decision. I could be wrong, but I suspect that it “just worked”, somebody figured it out, and the news spread.

If I understand your question, think of the slash in the taxonomy name as just another character.

Taxonomy URL of Taxonomy Page
blogcategories http://localhost:1313/blogcategories/
blog_categories http://localhost:1313/blog_categories/
blog/categories http://localhost:1313/blog/categories/

They should already be sorted alphabetically.

Thank you again!
I happened to find the namespace thing by chance, and I would not want to spread the word if it is an “accidental” thing, and it probably is otherwise we would be able to use such special characters in hugo code… If you wish we can delete this topic?
There is so much that happens automatically in Hugo that it seems magic, on the other hand I sometimes feel like I am not in control!

No need. It’s not a secret.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.