I’ve been looking through the documentation in order to find the best way to do this. I’m looking to have sections like this:
https://joltup.com/supportguide/ for my content pages. I want to create a page like that page. Is that possible?
Sure, I think you should be able to accomplish this using Hugo’s built-in .GroupBy method in your templating logic. You can then group by sections, date, etc. I believe you can also group according to your own custom variables as well. So, for example, you could set something like the following in the yaml of your individual files:
---
supportGroup: "Getting Started"
# Or "Temperature Sensors" or "Scheduling for Employees" or "Scheduling for Managers" (using your example site from joltup.com)
---
That was a great tipoff! I couldn’t get it to work though…Instead of grouping by, I decided to go this route.
<section id="menu">
<ul>
{{ range $key, $taxonomy := .Site.Taxonomies.categories }}
<li> {{ $key }} </li>
<ul>
{{ range $taxonomy.Pages }}
<li hugo-nav="{{ .RelPermalink}}"><a href="{{ .Permalink}}"> {{ .LinkTitle }} </a> </li>
{{ end }}
</ul>
{{ end }}
</ul>
</section>
My question now, is whether or not there would be any way to sort the taxonomy keys? By either the groupby or this strategy?
@tslater I definitely spoke too soon, since I hadn’t tested the methods I had originally proposed. [Here is a new support question] (https://discuss.gohugo.io/t/grouping-content-by-custom-metadata-and-then-sorting-by-custom-metadata-in-both-list-and-single-content-pages/2258) I just raised that has a lot in common with what you’re trying to do. You can use the built-in weight
for sorting, but like you, I’d like to extend my ability to sort.
Weight doesn’t apply to the taxonomies themselves, does it? Else where do you set the weight?
Taxonomies can be ordered by either alphabetical key or by the number of content pieces assigned to that key.
They can’t be ordered by a custom order though, can they?
Have you tried using the sort
template function?
@tslater Do you have this code in a GitHub repo? If so, I might be able to take a better look at what you’re trying to do. Thoughts?