Uh oh!
There was an error while loading. Please reload this page.
[4.x] Add option to link entries by slug - #8877
Conversation
jasonvarga
commented
Nov 1, 2023
Would you be able to provide a repo that shows real world usage of this? |
ryanmitchell
commented
Nov 1, 2023
Do you mean one using this PR, or a repo that uses a hierarchical collection in place of a taxonomy (but uses IDs for referencing)? |
I want to be able to an example of the hierarchy you're building, and then on top of that show why using slugs makes it better. Does that make sense? This PR is trying to make something already non-standard better. |
jasonvarga
commented
Feb 1, 2024
Closing for now, but happy to reopen when you get a chance to address it. |
ryanmitchell
commented
Feb 8, 2024
Sorry I missed this getting closed - I had sent over a repo by Discord (intentionally as it wasnt public) - showing how we do this. Was that not enough? |
This PR enables linking by slug in the entries fieldtype, making it possible to use collections in a similar way to taxonomies, i.e. your YAML can look like:
instead of:
The benefit of this is you can use a hierarchical approach.
As collections can be mounted we already have free routing.
If you want to output terms (the equivalent of the taxonomy
indexpage), you can then simply loop over the collection entries using a regular collection tag.If you want to output entries linked by a slug (the equivalent of the terms
showpage), you can get them as follows:{{ $linkedEntries= {collection:my_collection :pretend_terms_field:includes="slug"} }} Count: {{ $linkedEntries|count }} {{ $linkedEntries }} {{ title }} {{ /$linkedEntries }}To facilitate this you'll see I've added new query conditions (
includes,doesnt_include) which allow you to compare haystack arrays to needle strings (or arrays). This should probably replace #8357Left this as a draft to get your initial thoughts @jasonvarga. If you like the direction I'll add test coverage to get it ready for review.