Hi,
I’m currently migrating my blog from Jekyll to Hugo and also changing the theming etc. I’m posting as I wanted to get some suggestions on how I’m doing stuff and whether that’s “the right way to go” or whether there’s a better, more elegant way (which is pretty probably given I’m totally new to Hugo and Go in general).
I’m having a main blog list page (layouts/_default/list.html
) which internally uses a partial (postbox.html
) for rendering the single blog cards. Right now the 1st draft looks like this:
Now I also have categories (taxonomies) associated to each post. Hence I have a category list page which I’d like to slightly customize, just showing condensed cards with the icon and name. I created a layouts/category/list.html
where I have basically the same stuff as in my generic list, but I’m using a partial categorybox.html
for rendering the category card. And it works, looks like this:
Now however, if I click on a category, it displays all posts of that category, but using the layouts/category/list.html
which ofc doesn’t use the postbox.html
partial, but the categorybox.html
.
So basically I’d like to use a different version of the list template just for the overview list of my categories, but then fallback again to the same rendering as I use normally for all the posts. Right now I achieved what I wanted to have by using some “ifs” like
{{ if and (eq .Kind "taxonomy") (eq .Type "categories") }}
{{- partial "list-partials/categorybox.html" . -}}
{{ else }}
{{- partial "list-partials/postbox.html" . -}}
{{ end }}
{{end}}
But I’m sure there’s a better way to achieve this, right?
Thx a lot