Note: When I say “categories” it is not the default Hugo taxonomy. I have a Front Matter param on each product page that normally contains a SINGLE value. Ex.
Category: "Wood"
Tags: [ "widgets", "non-widgets" ]
or
Category: "Steel"
Tags: [ "widgets", "non-widgets" ]
This way I can create a page that loads cards for each product page on a Category Page (list.html). Here is the example of my code for listing all “non-widgets” in Category “steel”:
{{ $pageArray := where .Site.Pages ".Params.Category" "Steel" }}
{{ range where $pageArray.ByWeight "Params.tags" "intersect" (slice "non-widgets") }}
<div class="col-lg-4 col-md-6 d-flex py-2" data-aos="zoom-in" data-aos-delay="50">
<a href="{{ .Permalink }}" class="index-anchor">
<div class="card h-60">
{{ if .Params.categoryImage }}
{{ with .Resources.GetMatch .Params.categoryImage }}
<div class="card-img">
<img width="100%" src="{{ .RelPermalink }}" alt="{{ .Title }}" class="image-fluid">
</div>
{{ end }}
{{ end }}
<div class="card-body">
<h5 class="card-title"><a href="{{ .Permalink }}">{{ .Title | truncate 35 }}</a></h5>
<p class="card-text pb-2">
{{ .Summary | safeHTML | truncate 180 }} <br />
<div class="row justify-content-center"><a href="{{ .Permalink }}" class="btn"> Details...</a>
</div>
</p>
</div>
</div>
</a>
</div>
{{ end }}
{{ end }}
</div>
THE PROBLEM: I have a few products that fit in BOTH categories. I know that I can make an array in front matter for these products:
Category: [ "Wood", "Steel"]
Tags: [ "widgets", "non-widgets" ]
But I’m not sure how I would modify my category page code (example above) to find a product that fits both categories and load it’s card on both “Wood” and “Steel” category list pages.
And since I have a few product pages that fit both categories, does that mean that I need to turn the Front Matter param.Category for EVERY PRODUCT PAGE into an array (most containing only one value)?