I have a filter system on my website which uses categories. The categories have all got their own ID tagged to their HTML Element. Now I just need to get the clicked checkboxes to add their ID to the Twig variable which displays the entries in the for loop.

{% set categories = craft.categories.section('retrospect') %}

{% set relatedCategories = [] %}

{% for category in categories %}
  {% set relatedCategories = relatedCategories|merge([taggedIds]) %}
{% endfor %}

{% set related = craft.categories.section('retrospect').id(relatedCategories) %}

{% set relatedArticles = craft.entries.section('retrospect').relatedTo(related) %}

{% for entry in relatedArticles.order('caseNumber asc').after('2016-01').before('2016-12') %}
  {{ entry.title }}
{% endfor %}

The Twig code to fetch entries occurs on page load - Your JS code will run after the page loads and won't be able to update/fetch new entries. Instead, you should look at building a system that uses query strings to add the id's to the Twig variable on page load - then enhance this using AJAX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.