I need help with creating a content filter for my project.
I would like users to be able to select a location and then a product type and get all products that match the specified location and product type. Right now, I’ve got the location filer working, but I don’t know how to make the product type filter work.
Content structure:
content
pen
pen1.md
pen2.md
_index.md
pencil
pencil1.md
pencil2.md
_index.md
fountain-pen
fountain-pen1.md
fountain-pen2.md
_index.md
boston.md
newyork.md
Each file in a section (pen, pencil, fountain-pen) has the following front matter:
+++
company = ""
date = ""
description = ""
locations = [""]
productType = ""
title = ""
website = ""
+++
The productType
is either pen, pencil or fountain pen.
Each single page file (boston.md, newyork.md
) has the following front matter:
+++
date = ""
metadescription = ""
title = ""
type = "location"
+++
In index.html
I show a list of all the pens, pencils and fountain pens.
{{range (where .Site.RegularPages "Type" "not in" "location")}}
{{partial "products.html" .}}
{{end}}
I also have a location filter where all locations of each item is listed that I have created manually. This is done by creating a single page file for each location (boston.md, newyork.md
).
{{range (where .Site.RegularPages "Type" "in" "location")}}
<a href="{{.Permalink}}">{{.Title}}</a>
{{end}}
Once a user clicks on a location, such as Boston, the following code is generated in layouts > location > single.html
:
{{$fileName := title (humanize .File.TranslationBaseName)}}
{{range (where .Site.RegularPages "Type" "not in" "location")}}
{{if in .Params.locations $fileName}}
{{partial "products.html" .}}
{{end}}
{{end}}
This shows all products for Boston and has a url http://localhost:1313/boston/
. On this page, I would like to have a filter so a user can click on pen, pencil or fountain pen. If a user clicks on pen, the url changes to http://localhost:1313/boston/pen/
and shows all pens for Boston.
Not sure if this is important for you to know, but I will have 8 product types (pen, pencil etc) and 6-8 locations.
I’m sure this is possible, but I’m on the edge of my abilities here. So help, please?