Thanks @alexandros for your input, I’ll definitely have a look at the solution/workaround you are suggesting.
However I ended up doing another workaround using some “virtual” taxonomy, I mean by that that I set up a second taxonomy that is used in the front matter of my content but this taxonomy itself is never displayed :
- default “categories” taxonomy is used to display the actual content of the categories, in my case my products
- “productcategories” taxonomy is used to map the product to the actual category it refers to in the layout
So assuming that I want Product 1
to appear under subcategory A
, I will first define my virtual taxonomy in Product 1
content :
productcategories: ["subcategory A"]
Now to be able to display the correct products on each of my categories, I’ve defined the following on the list.html
layout of the categories taxonomy :
{{ $productcategory := .Title }}
{{ if isset .Params "productcategory" }}
{{ $productcategory := .Params.productcategory }}
{{ end }}
{{ range $key, $value := .Site.Taxonomies.productcategories }}
{{ if eq $key $productcategory }}
{{ range $value.Pages }}
<li class="product">
Product content appears here...
</li>
{{ end }}
{{ end }}
{{ end }}
Note : I didn’t need this on the product page because I simply don’t need to display category info when displaying a product, but I could have easily done the same thing on the product layout page !