Answers.Body: <p>It turns out that <code>getSupportedSites()</code> returns different results for categories and standard entries so an additional check needs to take place. </p>
  
  <p>The solution below has been tested with a single group with multiple languages, and it works, although I hope there's a better solution than this one:</p>
  
  <p>If the current page is a category then assign it to the entry variable</p>
  
  <pre><code>{% set entry = category %}
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code>{# Retrieve all supported sites for the current entry #}
  {% set supportedSites = entry.getSupportedSites %}
  
  &lt;ul&gt;
  {% for siteForEntry in supportedSites %}
    {% if siteForEntry | length == 1 %}
      {# category #}
      {% set site = craft.app.getSites.getSiteById(siteForEntry) %}
      {% set entryForOtherSite = craft.categories.id(entry.id).site(site).one() %}
    {% elseif siteForEntry | length == 2 %}
      {# standard entry #}
      {% set site = craft.app.getSites.getSiteById(siteForEntry.siteId) %}
      {% set entryForOtherSite = craft.entries.id(entry.id).site(site).one() %}
    {% endif %}
  
    {% if site.id == entry.siteId %}
        {# This is the current language, mark it as active and don't retrieve its url #}
        &lt;li class="current"&gt;&lt;a href="#"&gt;{{site.language}}&lt;/a&gt;&lt;/li&gt;
    {% else %}
        {# if it's not the current site, get the entry for this site #}
        &lt;li&gt;&lt;a href="{{ entryForOtherSite.getUrl() }}"&gt;{{site.language}}&lt;/a&lt;/li&gt;
    {% endif %}
  
  {% endfor %}
  &lt;/ul&gt;
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-31T09:18:58.363Z
Answers.LastActivityDate: 2018-05-31T09:18:58.363Z
Answers.UserDisplayName: Panos Spiliotis
Body: <p>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. </p>
  
  <p>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. </p>
  
  <p>For single entries I do the following (simplified):</p>
  
  <pre><code>{% for siteForEntry in entry.getSupportedSites %}       
      {% set site = craft.app.getSites.getSiteById(siteForEntry.siteId) %}        
      {% if site.id == entry.siteId %}
          &lt;li class="language-selection--active-language"&gt;
             &lt;a href="#"&gt;{{ site.language }} &lt;/a&gt; 
          &lt;/li&gt;
      {% else %}            
          {% set entryForOtherSite = craft.entries.id(entry.id).site(site).one() %}
              &lt;li class="{% if site.id == entry.siteId %} language-selection--active-language{% endif %} "&gt;
                  &lt;a href="{{ entryForOtherSite.getUrl() }}"&gt;{{ site.language }} &lt;/a&gt;
               &lt;/li&gt;
          {% endif %}
   {% endfor %}
  </code></pre>
  
  <p>Is there a way to do the same thing for categories?</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-30T19:30:55.337Z
Comments.Text: What about changing every `entry` to `category` and running your code again?
Comments.UserDisplayName: Robin Schambach
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-05-31T09:19:50.153Z
Comments.Text: It won't work because `getSupportedSites ` returns different things for entries and categories. See my answer below.
Comments.UserDisplayName: Panos Spiliotis
Tags: <craft3>
Title: Is there a way to get supportedSites for a category page?
ThreadText: # Is there a way to get supportedSites for a category page?
  
  (Asked by: username_0 on 2018-05-30)
  
  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?
  
  **Tags:** craft3
  
  > **Comments:**
  > **username_1**: What about changing every `entry` to `category` and running your code again?  
  > **username_0**: It won't work because `getSupportedSites ` returns different things for entries and categories. See my answer below.  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2018-05-31. Score: 1
  
  It turns out that `getSupportedSites()` returns different results for categories and standard entries so an additional check needs to take place.
  
  The solution below has been tested with a single group with multiple languages, and it works, although I hope there's a better solution than this one:
  
  If the current page is a category then assign it to the entry variable
  
  ```
  {% set entry = category %}
  
  ```
  
  Then:
  
  ```
  {# Retrieve all supported sites for the current entry #}
  {% set supportedSites = entry.getSupportedSites %}
  
  <ul>
  {% for siteForEntry in supportedSites %}
    {% if siteForEntry | length == 1 %}
      {# category #}
      {% set site = craft.app.getSites.getSiteById(siteForEntry) %}
      {% set entryForOtherSite = craft.categories.id(entry.id).site(site).one() %}
    {% elseif siteForEntry | length == 2 %}
      {# standard entry #}
      {% set site = craft.app.getSites.getSiteById(siteForEntry.siteId) %}
      {% set entryForOtherSite = craft.entries.id(entry.id).site(site).one() %}
    {% endif %}
  
    {% if site.id == entry.siteId %}
        {# This is the current language, mark it as active and don't retrieve its url #}
        <li class="current"><a href="#">{{site.language}}</a></li>
    {% else %}
        {# if it's not the current site, get the entry for this site #}
        <li><a href="{{ entryForOtherSite.getUrl() }}">{{site.language}}</a</li>
    {% endif %}
  
  {% endfor %}
  </ul>
  
  ```
  
  
  ---
  
  