-
-
Notifications
You must be signed in to change notification settings - Fork 551
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Custom Taxonomy Routes #2403
Comments
Hey @warkior |
+1 for this. Working with taxonomy routes and having them Just Work™ is a little harder in v3. It would be nice to be able to define a custom route and still have access to the data, like on the default routes, available there too. |
+1 for this as well. We also heavily relied on custom routing functionality. And we do not use a similar structure as @warkior as we use taxonomies both as content as well as filtering for blog items for instance. I'm going to check if we can use this workaround, but I am afraid it will not be compatible. |
I have come to the conclusion that we cannot implement the workaround as suggested. So we are now forced to migrate the taxonomy to a collection instead, as it allows us to use a custom routing scheme. This is really disappointing as this breaking change is not even documented on the https://statamic.dev/upgrade-guide#breaking-changes-core page. |
@FrankPeters You can still define custom routes in your
I do wish it was possible to 'attach' a taxonomy to a route like the one above, though. |
@JonKaric Thanks! It seems to have worked. This will save a ton of work. Still have to solve some issues, but they appear minor now compared to converting to collections ;-) |
@FrankPeters Oops, pretty sure it wasn't intentionally left off the list of breaking changes. Thanks for pointing that out though. I've PR'd it into the docs statamic/docs#319. |
This issue has not had recent activity and has been marked as stale — by me, a robot. Simply reply to keep it open and send me away. If you do nothing, I will close it in a week. I have no feelings, so whatever you do is fine by me. |
Re-opening this |
Docs suggestion being able to define the route in the YAML file for the taxonomy https://statamic.dev/knowledge-base/taxonomies-by-hand#creating-taxonomies but that doesn't work
However when I loop through the tags
the output is still |
I'm hitting this same problem. Is there a fix on the horizon? Is the issue related to the need for a taxonomy subfolder in a collection? |
You're able to have collection-specific taxonomy routes. https://statamic.dev/taxonomies#templating e.g. if you create |
yeah, that works but if you wanted to customise the route further? I have a site on v2 that has a particular routing structure they don't want to move from. I've been able to circumvent via some gnarly route file magic. |
Just pointing that out since some comments sound like they didn't know that was possible. |
sure - I've not had any issues on new builds but definitely a quirk on a migration |
I guess I was wondering if it's possible to drop the taxonomy name from the URL? When viewing |
@stephenmeehanuk where are your blog posts located? /blog/{slug}? wouldn't that conflict with /blog/{tag}? |
@jasonvarga I guess there would be a conflict... I'm curious how this bit works though. Using the example from the docs, on Based on the need for the taxonomy slug to be present in the URL for the collection term page, I would expect it to be used in the entry url - but it's not? |
Where are you getting that from? The URL of the entry is defined in the |
Apologies, I had the wrong end of the stick! I get taxonomy URL and collection URL are two different things. Are there (any near future) plans to bring back custom taxonomy routes as mentioned at the top of this post? Or fixing the issue @1stevengrant mentions? Seems like the docs say custom taxonomy routes are possible, but it's not working? Currently I need to use this structure when using a taxonomy with a collection I think in most cases I could live with the default structure
It'd be neat if I didn't need to expose the taxonomy name in the URL The custom route options for collections work really well, could something similar be applied to taxonomy routes in a future release? |
I'd like to support it at some point since people clearly want it. I don't have an ETA though. I've fixed Steven's issue with the docs by removing it. 😄 |
😂 |
@stephenmeehanuk here's how I've worked around it Route::get('whats-on/festival/{slug}', function ($slug) {
$festival = Term::findBySlug($slug, 'festival');
return (new \Statamic\View\View)
->layout('layout')
->template('events.festival')
->with(['title' => $festival->title()]);
}); |
Here's a gist with an example of how to implement custom taxonomy routes. It builds on what Steven posted. https://gist.github.com/jasonvarga/4342f96b77d52fcd27dad22d88253e1f |
The various comments above have been very helpful. Here's a way we've solved it for now. We've added the following to our Route::get('magazine/topics/{slug}', function ($slug) {
/** @var \Statamic\Taxonomies\LocalizedTerm $term */
$term = Term::findBySlug($slug, 'magazine_topic');
if( !$term )
return response((new \Statamic\View\View)
->layout('layout')
->template('errors.404'), 404);
return (new \Statamic\View\View)
->layout('layout')
->template('magazine_topic.show')
->with([
'title' => $term->title(),
'slug' => $slug,
] + $term->data()->toArray());
}); This allows page loads of We are then able to use the following in {{ collection from="magazine_articles" taxonomy:magazine_topic="{slug}" paginate="true" as="posts" }}
...
{{ posts }}
<h3> {{ title }} </h3>
...
{{ /posts }}
...
{{ /collection }} Hope this is helpful to someone out there. :) |
I have the strange case where on my development and staging environments the Where should I look for the issue? |
Bug Description
We seem to have lost the ability to use custom taxonomy routes.
I have a taxonomy named
Magazine Topic
. It seems to also suffer from issue #2273.On Statamic v2 we had defined a custom route for the taxonomy to use /magazine/topic/{slug}. I don't seem to be able to reproduce it on Statamic v3.
Statamic version: 3.0.7
PHP version: 7.3
The text was updated successfully, but these errors were encountered: