I have a list of entries, with an option to filter them by categories.
If no filter is applied, clicking an entry should (and does) take you to the permalink URL for that entry, as defined in the section settings:
<a href="{{ entry.url }}">{{ entry.title }}</a>
Results in:
<a href="/beverages/gin">Gin</a>
However, if a filter is applied, I'd like to "remember" the category, and apply it to the entry's {{ entry.getNext() }}
-style pagination.
In other words, imagine a "Consumables" section, with entries of "Gin", "Lasagne", "Noodles", & "Vodka" (with the obvious categories of "Beverages" and "Food"). You filter the entries on the listing page by the "Beverages" category, & click on the "Gin" entry therein. What I want is for the "Next Entry" link on Gin's page to go to "Vodka", not "Lasagne".
So far, the solution I came up with is to modify the URL for when entries are filtered so that the applied filter results in a URL of /consumables/category/beverages
. I also have a route set up so that when a fourth segment is present, it tries to match it up with an entry, eg. /consumables/category/beverages/gin
.
Now, I don't know if this is the best solution for this issue, but if it is, the remaining problem is figuring out how to modify the links to the entries on filtered pages so that they include the category. Something like {{ entry.url('consumables/category/' ~ entry.category)
would be nice, but it doesn't seem to work like that.