Hi Everyone,
I am a new used to Hugo and I’ve been developing my own site and Theme. I’ve got the basic wireframe built, I’ve managed to get compiled CSS working. I am having trouble getting my head around Hugo Functions and how they work. In an effort to solve this, I have read almost the entirety of the current Hugo Docs site, watched all the Hugo Youtube clips and read Google for hours. I am still struggling to understand Hugo Functions. I’ve also read 50 or more range
posts here in the hopes I might understand.
For example, I want to get a list of categories for my blog. I will use this on my front page and when you go to /blog/
The function I am using is:
{{ range $key, $value := .Site.Taxonomies.categories }}
<a class=blog-panel-category item{{ printf "%s/%s" $key }}
href="/categories/{{ $value | urlize }}">{{ $key | title }}</a>
{{ end }}
I would like to get the index for each of the entries, hence item{{ printf "%s/%s" $key }}
, which does not seem to work. I am using this in my CSS.
I would like to order the categories based on the number of articles each category has (ascending).
On my front page, I would like to restrict the number of categories returned to 9.
On my /blog/
page, I want to sort alphabetically.
I do not understand what the $key, $value values that are returned and why they change when I change the function from .Site.Taxonomies.categories
to .Site.Taxonomies.categories.Alphabetical.Reverse
. I am also not understanding scope when I have functions that are nested, like this example - Reverse taxonomy order
I was wondering if someone could give me some function examples on how to create what I want but also explain some of my questions above or point me towards an article that explains things in newbie terms?