Closed robdekort closed 3 years ago
Loop with {{ terms }} instead of the {{ taxonomy }} tag.
Hey Jason. Yeah I tried that but {{ terms }} doesn't return anything in my case. Hmmm.
I notice in your screenshot that your URL is categories but the contents show tags. How many taxonomies do you have? Tags and Categories?
If you're on /blog/categories, {{ terms }} would be outputting terms within the categories
taxonomy. Do you have any categories terms?
I've got two taxonomies here. I must've mixed and matched those examples wrong for you.
But unfortunately terms didn't output terms belonging to the taxonomy. Will verify again in a few.
Verified, check this with the {{ taxonomy }}
tag:
And this with the {{ terms }}
tag:
Hope it makes sense.
Do you have any category terms?
Yep, see that first screenshot. One term, which is called Category 2. That name doesn't make any sense whatsoever so sorry for that. I guess there were multiple terms during my testing at some point ;-). So it's being fetched when using the {{ taxonomy }}
tag. However in the bottom one you can see using {{ terms }}
doesn't return anything in this case.
You can check out this PR if you want: https://github.com/studio1902/statamic-peak/tree/feature/update-seo
I was playing with taxonomies to improve the SEO features and stumbled upon it.
If it helps, a copy of the site: taxonomies.zip
Ah it filters by terms that are actually used in that collection.
You don't have any entries that use any categories, so you get no results.
You're seeing "Categories" and "/blog/categories" because it's falling back to the current page. You can use a no_results
condition to output something nicer.
{{ terms }}
{{ if no_results }}
No terms.
{{ else }}
{{ title }} {{ url }}
{{ /if }}
{{ /terms }}
Ah that's how the term tag works exactly. The no_results thing is the way indeed. Just playing here so no need to make it pretty :-).
But then the original issue/post still stands right? That the taxonomy
tag should return the url for each term including the collection slug since it's mounted and attached to that collection?
The taxonomy
tag doesn't do anything special with the collection unless you tell it to. You could do {{ taxonomy:categories collection="blog" }}
if you wanted. But that's what {{ terms }}
is doing for you automatically.
Not sure if I explained the issue right. Ping me if you want. Happy to explain.
Jason explained it to me. I get it now, for anyone running into this, it's not a bug, it's a feature :-)
{{ terms }}
will list the taxonomies with the collection handle included the URL since it lists taxonomies tied to entries in this collection.
{{ taxonomy }}
will list all terms without any collection handle in the URL. And this does make sense since you could attach taxonomies to multiple collections for instance. The tag knows nothing about any collection you might be currently visiting.
You can force it to know about the collection with {{ taxonomy:handle collection="blog" }}
, but it will still only show terms that are used in that collection. Same as {{ terms }}
.
Bug description
When you have a taxonomy assigned to a collection and that collection mounted to an entry you should get the following taxonomy route:
{collection_mount_handle}/{taxonomy_handle}/{term_slug}
On the index template right here:
collection_handle/taxonomy_name/index
Which is then reachable under the following url:
{mount_handle}/{taxonomy_handle}/
You can loop through your terms using:
This however returns the wrong URL for terms. It doesn't include the slug for the entry you mounted your collection.
Notice the URL in the address bar + the term URL's in the loop here:
It should be prefixed with
/blog
.How to reproduce
Logs
No response
Versions
Statamic 3.2.15 Pro Laravel 8.64.0 PHP 7.4.13 No addons installed
Installation
Starter Kit using via CLI
Additional details
No response