Taxonomy terms do not render when sorted by weight

#1

Hi everyone,

First I am fairly new to hugo and really did try my best to search the doc and the forums. I apologies in advance if this is an easy fix or not really worth anyone’s time here.

What I am trying to do:
Sort the terms of the month taxonomy in a specific order (by default it is coming out in alphabetical order).

What I have done so far
Here is what my partial looks like:

<div class="months">
    <div class="container">
        {{ $pageUrl := .URL }}
        {{range $name, $taxonomy := .Site.Taxonomies.month.ByWeight}}
            {{ if in $pageUrl $name }}
                <a class="month-link month-is-active" href="/month/{{$name}}">{{$name}}</a>
            {{else}}
                <a class="month-link" href="/month/{{$name}}">{{$name}}</a>
            {{end}}
        {{end}}
    </div>
</div>

Here’s what the front matter looks like for two different entry:

month:
    - December
month_weight: 2

month:
   - November
month_weight: 1

For some reason nothing renders and I have no error. This was my partial before using weight:

<div class="months">
    <div class="container">
        {{ $pageUrl := .URL }}
        {{range $name, $taxonomy := .Site.Taxonomies.month}}
            {{ if in $pageUrl $name }}
                <a class="month-link month-is-active" href="/month/{{$name}}">{{$name}}</a>
            {{else}}
                <a class="month-link" href="/month/{{$name}}">{{$name}}</a>
            {{end}}
        {{end}}
    </div>
</div>

This output the two different month but sort them in alphabetical order as mentioned above.

#2

I think all you need to do is go back to your original partial and just add .ByWeight to the range statement.

{{range $name, $taxonomy := .Site.Taxonomies.month.ByWeight}}
#3

Thanks for taking the time to comment on my issue!

Sorry I forgot to mention how I got to use the former example rather than just adding .ByWeight to my original code.
Both {{range $name, $taxonomy := .Site.Taxonomies.month.ByWeight}} and {{range .Site.Taxonomies.month.ByWeight}} prints nothing while returning no error.

EDIT: Changed my post to use the former snippet of code with .ByWeight added

#4

If you follow the advice at Requesting Help and share your site code, you’ll have more people helping. If you can’t share your project, start a new, smaller project that reproduces the issue and share that. :slight_smile: