Skip to main content
added 62 characters in body
Source Link
sarah3585
  • 899
  • 7
  • 14

I have the following setup for a language switcher. I have Member Directory pages which are using Users (rather than Entires or Categories). How can I update this to get it working on these pages?

{% set langSwitcher = craft.app.sites.getAllSites() %}

<div class="flag">
 {% for lang in langSwitcher %}
 {# Set homepage as default #}
 {% set url = alias(lang.baseUrl) %}

 {# Entry is defined #}
 {% if entry is defined %}
  {# Check if that entry exists in other locale #}
  {% set otherLocaleEntry = craft.entries.siteId(lang.id).id(entry.id).one() %}
  {% if otherLocaleEntry %}
    {% set url = otherLocaleEntry.url %}
  {% endif %}

{# Category is defined #}
{% elseif category is defined %}
  {# Check if that entry exists in other locale #}
  {% set otherLocaleCat = craft.categories.siteId(lang.id).id(category.id).one() %}
  {% if otherLocaleCat %}
    {% set url = otherLocaleCat.url %}
  {% endif %}
{% endif %}

 <div {% if lang.id == currentSite.id %}class="active"{% endif %}>
  <a href="{{url}}" > <img src="/assets/images/site/flag-{{lang.name|lower}}.svg" alt="{{lang.name|upper}}"></a>
 <p class="small-hide"><a href="{{url}}" >{{lang.name|upper}}</a></p>
 </div>

{% endfor %}

I have the following setup for a language switcher. I have Member Directory pages which are using Users (rather than Entires or Categories). How can I update this to get it working on these pages?

<div class="flag">
 {% for lang in langSwitcher %}
 {# Set homepage as default #}
 {% set url = alias(lang.baseUrl) %}

 {# Entry is defined #}
 {% if entry is defined %}
  {# Check if that entry exists in other locale #}
  {% set otherLocaleEntry = craft.entries.siteId(lang.id).id(entry.id).one() %}
  {% if otherLocaleEntry %}
    {% set url = otherLocaleEntry.url %}
  {% endif %}

{# Category is defined #}
{% elseif category is defined %}
  {# Check if that entry exists in other locale #}
  {% set otherLocaleCat = craft.categories.siteId(lang.id).id(category.id).one() %}
  {% if otherLocaleCat %}
    {% set url = otherLocaleCat.url %}
  {% endif %}
{% endif %}

 <div {% if lang.id == currentSite.id %}class="active"{% endif %}>
  <a href="{{url}}" > <img src="/assets/images/site/flag-{{lang.name|lower}}.svg" alt="{{lang.name|upper}}"></a>
 <p class="small-hide"><a href="{{url}}" >{{lang.name|upper}}</a></p>
 </div>

{% endfor %}

I have the following setup for a language switcher. I have Member Directory pages which are using Users (rather than Entires or Categories). How can I update this to get it working on these pages?

{% set langSwitcher = craft.app.sites.getAllSites() %}

<div class="flag">
 {% for lang in langSwitcher %}
 {# Set homepage as default #}
 {% set url = alias(lang.baseUrl) %}

 {# Entry is defined #}
 {% if entry is defined %}
  {# Check if that entry exists in other locale #}
  {% set otherLocaleEntry = craft.entries.siteId(lang.id).id(entry.id).one() %}
  {% if otherLocaleEntry %}
    {% set url = otherLocaleEntry.url %}
  {% endif %}

{# Category is defined #}
{% elseif category is defined %}
  {# Check if that entry exists in other locale #}
  {% set otherLocaleCat = craft.categories.siteId(lang.id).id(category.id).one() %}
  {% if otherLocaleCat %}
    {% set url = otherLocaleCat.url %}
  {% endif %}
{% endif %}

 <div {% if lang.id == currentSite.id %}class="active"{% endif %}>
  <a href="{{url}}" > <img src="/assets/images/site/flag-{{lang.name|lower}}.svg" alt="{{lang.name|upper}}"></a>
 <p class="small-hide"><a href="{{url}}" >{{lang.name|upper}}</a></p>
 </div>

{% endfor %}
Source Link
sarah3585
  • 899
  • 7
  • 14

Language Switcher with Users

I have the following setup for a language switcher. I have Member Directory pages which are using Users (rather than Entires or Categories). How can I update this to get it working on these pages?

<div class="flag">
 {% for lang in langSwitcher %}
 {# Set homepage as default #}
 {% set url = alias(lang.baseUrl) %}

 {# Entry is defined #}
 {% if entry is defined %}
  {# Check if that entry exists in other locale #}
  {% set otherLocaleEntry = craft.entries.siteId(lang.id).id(entry.id).one() %}
  {% if otherLocaleEntry %}
    {% set url = otherLocaleEntry.url %}
  {% endif %}

{# Category is defined #}
{% elseif category is defined %}
  {# Check if that entry exists in other locale #}
  {% set otherLocaleCat = craft.categories.siteId(lang.id).id(category.id).one() %}
  {% if otherLocaleCat %}
    {% set url = otherLocaleCat.url %}
  {% endif %}
{% endif %}

 <div {% if lang.id == currentSite.id %}class="active"{% endif %}>
  <a href="{{url}}" > <img src="/assets/images/site/flag-{{lang.name|lower}}.svg" alt="{{lang.name|upper}}"></a>
 <p class="small-hide"><a href="{{url}}" >{{lang.name|upper}}</a></p>
 </div>

{% endfor %}