Standard tag pages list content for one tag (e.g.,/tags/python/). But sometimes users want to find content that matches multiple criteria, like "Tutorials" AND "Python" AND "Beginner".
This guide shows how to build an advanced filter using Jinja set logic.
The Logic: Set Intersections
Jinja allows us to treat lists of pages as mathematical sets.
- Union: All unique items in A or B.
- Intersection: Items that are in BOTH A and B.
- Difference: Items in A but not in B.
Example: Building a "Recipe Finder"
Imagine a documentation site where you want to find "API Guides" for "v2.0".
1. Accessing the Data
Bengal exposessite.taxonomieswhich gives us lists of pages for each tag.
1 2 | |
2. Finding the Intersection
We can find pages that exist in both lists.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | |
Advanced: The "Filter Page" Layout
For a dynamic filter page (e.g.,/search/), we typically rely on client-side JavaScript because pre-rendering every combination of tags is expensive (combinatorial explosion).
However, for specific, high-value combinations, you can create dedicated pages.
Step 1: Create the Page
site/content/guides/python-tutorials.md:
1 2 3 4 5 6 | |
Step 2: Create the Layout
templates/filter_page.html:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | |
Summary
Use Set Intersections to build powerful "Topic Pages" that aggregate content from multiple dimensions without manually curating lists.
Seealso
- Content Reuse — DRY content strategies
- Templating — Jinja2 fundamentals