I have a list page with content from related pages that all have a number of categories assigned in their frontmatter. I want to show all content initially, but give the option to show only specific content based on user selection with Alpine.js. There are numerous examples online how this can be done, but I seem to fail at the point where I populate the categories and compare them to the user input.
The categories do show in the select dropdown. I can also get the individual pages’ categories as [category1 category2 category3], but I cannot manage to check if the selection equals/intersects/is in one of the categories of each page. (or am probably making more mistakes). Thank you for your help!
This is my code:
<div x-data="{ selected: 'placeholder' }">
<select x-model="selected">
<option value="placeholder" selected disabled>Select</option>
{{ $categories := $.Site.Taxonomies.categories.Alphabetical }}
{{ range $categories }}
{{ if .Term }}
<option value=".category-{{ .Term }}" x-hide:selected="selected === .category-{{ .Term }}">{{ .Term }}</option>
{{ end }}
{{ end }}
</select>
{{ range .Pages }}
<div x-show="selected == {{ .Params.Categories }}" x-cloak>
<a href="{{ .RelPermalink }}">
<img src="{{ .Params.coverimage }}">
{{ .Title }}
</a>
</div>
{{ end }}
</div>