I have several hundred products with the following front matter:
countries = []
description = ""
title = ""
I need to generate a list of unique countries used and a code reference for each. As an example with the following products:
countries = ["Australia", "Canada"]
description = ""
title = ""
countries = ["Australia"]
description = ""
title = ""
countries = ["Belgium", "New Zealand"]
description = ""
title = ""
I would like the list to be:
country_id: "c_australia",
country: "Australia"
country_id: "c_belgium"
country: "Belgium",
country_id: "c_canada"
country: "Canada",
country_id "c_new_zealand:
country: "New Zealand"
I’ve tried doing:
{{range .Site.RegularPages}}
{{.Params.countries}}
{{end}}
which gives the list:
["Australia", "Canada"]
["Australia"]
["Belgium"]
["Canada", "New Zealand"]
This is not what I want as it repeats Australia twice. I tried adding uniq to my code like so:
{{range .Site.RegularPages}}
{{.Params.countries | uniq}}
{{end}}
But no change. I’m also not sure how to break up each country and add the country_id. Any help please?