Hello,
I think I have a ‘context’ problem. I would really appreciate some help.
I have a site section “Library” which has sub-pages that will each have a content category (could be one of 3). I’ve chosen not to use the site-wide taxonomy/category system because these categories are unique to this site section, and I don’t want the auto-generated category pages. However, I would appreciate any useful feedback on this decision, too.
I have listed these categories and some aspects of them in the front matter of the Library _index.md:
[[contentCategories]]
plural = "Publications"
singular = "Publication"
url = "publications"
[[contentCategories]]
plural = "Documents"
singular = "Document"
url = "documents"
[[contentCategories]]
plural = "Other"
singular = "Other"
url = "other"
and on each piece of content within the Library that I want to list on the index page, I have set in the front matter a contentCategory, e.g.:
contentCategory = "Publication"
I have a tabbed interface on the Library index page, with following ranges, which isn’t working:
{{ range .Params.contentCategories }}
<!-- code to generate tops of tabs using .plural and .url (this works) -->
{{ range ((where .Pages "contentCategory" "eq" .Params.contentCategories.singular) sort .Pages "date") }}
<!-- code to list out each piece of library content using its front matter parameters -->
{{ end }}
{{ end }}
The first goes through the contentCategories tables to create each tab; the inner range is attempting to go through the pages within the Library section and check if the content’s contentCategory matches the singular term of the corresponding one in contentCategories, to display it within that particular category’s tab, sorted by date.
This gives the error "Error while rendering “section” in “library/”: template: library/list.html:38:13: executing “main” at <where .Pages "conten…>: error calling where: can’t iterate over
I’m guessing this this because I can’t access .Pages from within the first front matter table loop. I know this is also not the best way to do this, but I have no idea 1. what’s best and 2. how to actually write this using similar (but different) examples here and here
I am unable to share the repo due to company policy.
Please could anyone offer advice? Many thanks.