Access taxonomy with slash inside it's name via .Site.Taxonomies

Hello.
I have my taxonomies like so:

[taxonomies]
 
    tag = 'tags'

    movie_author = 'movies/authors'
    movie_genre = 'movies/genres'
    movie_year = 'movies/years'
    movie_rating = 'movies/ratings'

    music_author = 'music/authors'
    music_genre = 'music/genres'
    music_year = 'music/years'
    music_rating = 'music/ratings'

    book_author = 'books/authors'
    book_genre = 'books/genres'
    book_year = 'books/years'
    book_rating = 'books/ratings'

and front-matter like so:

+++
title = 'some title'
"music/authors" = 'some author'
"music/genres" = ['genre1, 'genre2']
"music/years" = '2013'
"music/ratings" = '4'
tags = ['Tag1', 'Tag2']
+++

I can access the tags taxonomy with {{ .Site.Taxonomies.tags }}, but how can I access others?
I’ve tried {{ .Site.Taxonomies.movies/years }} but obviously it doesn’t work.

Thanks.

solution link

I am not saying that you can’t have taxonomies with slashes in their names (I don’t know that), but I think it’s a bad idea. A slash is a folder-separation thing. So, basically, you would have to backslash the hell out of it to make it disappear in folder structures, and that is always a sign of an issue down the road.

I did not spend time to try this out, but try the following (just typed it, not tested):

{{ range $index, $slug: .Site.Taxonomies }}
<ul>
<li>index: {{ $index }}
<li>slug: {{ $slug }}
</ul>
{{ end }}

that might show your “weird” taxonomies. I think they might end up as for instance music\\/authors. Or even something weirder. If they don’t show up at all take it as a sign that slashes in taxonomy titles are not allowed.

Do yourself a favor and rename your taxonomies to something like music_authors, music_genres, etc.

You probably did this because you might have not known that you could add the following to your content in for instance content/music_authors/authorname/_index.md:

---
title: music/authors/authorname
---

and in content/music_authors/_index.md:

---
title: music/authors
---

This way your taxonomies can have whatever name you want them to have, while keeping things simple for your layout files.

see here: Taxonomies | Hugo

1 Like

Thank you for your helpful response!
Will try to do it your way.

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

This is the idiomatic way to render terms assigned to a page, regardless of whether the taxonomy is nested:

{{ with .GetTerms "movies/authors" }}
  <p>Movies/authors:
    {{ range . }}
      <a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a>
    {{ end }}
  </p>
{{ end }}

Using the GetTerms method is less fragile than using the printf function to build a link to the term page.

1 Like