I'm working on a site that is available in multiple languages and I would like to build a language switcher that will work for both category pages and single entries.
In Craft v2 that was possible but once I switched to Craft v3, I can't find a way to do get the current category page.
For single entries I do the following (simplified):
{% for siteForEntry in entry.getSupportedSites %}
{% set site = craft.app.getSites.getSiteById(siteForEntry.siteId) %}
{% if site.id == entry.siteId %}
<li class="language-selection--active-language">
<a href="#">{{ site.language }} </a>
</li>
{% else %}
{% set entryForOtherSite = craft.entries.id(entry.id).site(site).one() %}
<li class="{% if site.id == entry.siteId %} language-selection--active-language{% endif %} ">
<a href="{{ entryForOtherSite.getUrl() }}">{{ site.language }} </a>
</li>
{% endif %}
{% endfor %}
Is there a way to do the same thing for categories?
entry
tocategory
and running your code again?getSupportedSites
returns different things for entries and categories. See my answer below.