O, thank you!!! Exactly! The first approach worked! After things come to the worst they will inevitably start changing to the better.
May be you can understand what’s going on here?
{{ range $name, $items := .Site.Taxonomies.products }}
It crashes if I add where clause
{{ range where .Pages “categories” “women” $name, $items := .Site.Taxonomies.products }}
with error message ‘undefined variable “$name”’
Taxonomies and products (.md file) look like this:
[taxonomies]
product = “products”
products: [“watches”]
I tried comparing it as a slice - it’s not enough.
I have reformulated my task at hand in a clearer way. This is a content filter - it reads product-description.md files in /content folder and subfolders. I have product-description.md files in two subfolders /content/women and /content/men.
If I open /women page - Hugo uses /layouts/_default/list.html to list content from /content/women folder, if /men - from /content/men folder. Content filter code (below) is located on the list.html page.
I want the content filter code to determine if list.html is opened as /women or /men and to list content only from this folder.
Here is the content filter code that lists products and enumerates them:
<section class="widget widget-products mb-5">
<h3 class="widget-title mb-4">Products</h3>
{{- if isset .Site.Taxonomies "products" }}
{{- if not (eq (len .Site.Taxonomies.products) 0) }}
<ul class="list-unstyled">
{{- range $name, $items := .Site.Taxonomies.products }}
<li>
<a class="cat-item d-lg-flex justify-content-between text-dark"
href="{{ `products/` | relLangURL }}{{ $name | urlize | lower }}">{{ $name | title | humanize }}<span>{{len $items}}</span></a>
</li>
{{- end }}
</ul>
{{- end }}
{{- end }}
</section>
Great, thank you for looking into this! So, the second method worked for you. It didn’t work for me - but the 1st one worked for me. Now it would be great if you can think about the content filter “range where”. thank you.
I understand why you have used a taxonomy for categories. A product could be intended for men:
categories = ["men"]
or women:
categories = ["women"]
or both:
categories = ["men", "women"]
A product, on the other hand, is either a Bag or a Watch; it cannot be both. Our lives would be easier if we could use a simple string in front matter to classify the product, instead of a taxonomy term. If we can use a simple string, we will be able to use GroupByParam to count the number of each class of women’s products.
Exactly. The category defines one or more product groups, while a product is either this or that. I could not find a way to rewrite this expresson to do the taks - I hope you can.