I'm having trouble outputting a list of tags that only includes tags from the current locale.
Here's the setup:
- I have a site with two locales: english and spanish
- I have a section with handle newsAndEvents
- I have a tag field with handle newsTags on entries in that section that is set to translatable to allow my clients to assign locale-specific tags to the entries
- I have an entry in that section created with a published version for each of my locales. In the english version, I've added a tag "Turtles" to the entry. In the spanish version, I've added a tag "Tortugas" to the entry.
On the landing page of my news section, I am displaying a list of recent tags in a sidebar. Here's the code I'm using to do it:
{# grab the entries in the specific locale #} {% set entries = craft.entries.find({section: 'newsAndEvents', locale: craft.locale}) %} {# Grab the related tags for those entries #} {% set tags = craft.tags.relatedTo(entries) %} {# Build the list #} {% if tags | length %} <ul class="tag-list"> {% for tag in tags %} <li><a class="tag" href="#">{{ tag.name }}</a></li> {% endfor %} </ul> {% endif %}
- The problem is, when I'm looking at the english version of my landing page, I get both "Tortugas" and "Turtles" in the list output by the code above. What I want is to only see the tags on english versions entries on the english landing page; and the tags on spanish versions of entries on the spanish landing page.
Some additional info:
If an entry has only one published version, english for example, any tags I assign to that version do not appear on the spanish landing page, as would be expected.
On my entry detail pages, I'm using similar code to generate a list of tags assigned to the current entry, and the output is what I expect: english versions only show tags assigned to english versions, not to both english and spanish like on the landing page.
What am I missing?