Commit a7804242 authored by ancoats's avatar ancoats
Browse files

Use language display name and implement base URL fallback in language switcher

parent b31c7b6b
......@@ -8,22 +8,23 @@
<ul class="c-nav__list">
{% for site in craft.app.sites.getAllSites %}
{% if entry is defined %}
{% set localeEntry = craft.entries.siteId(site.id).id(entry.id).one() %}
{% set url = localeEntry ? localeEntry.url : alias(site.baseUrl) %}
{% if (entry is defined) %}
{% set entryByLocale = craft.entries.siteId(site.id).id(entry.id).one() %}
{% set url = (entryByLocale ? entryByLocale.url : alias(site.baseUrl)) %}
{% elseif category is defined %}
{% set localeCat = craft.categories.siteId(site.id).id(category.id).one() %}
{% set url = localeCat ? localeCat.url : alias(site.baseUrl) %}
{% elseif (category is defined) %}
{% set categoryByLocale = craft.categories.siteId(site.id).id(category.id).one() %}
{% set url = (categoryByLocale ? categoryByLocale.url : alias(site.baseUrl)) %}
{% elseif user is defined %}
{% set localeAncestor = craft.entries.siteId(site.id).section('pageLocalGroups').one() %}
{% set url = localeAncestor ? (localeAncestor.url ~ '/' ~ user.username) : alias(site.baseUrl) %}
{% else %}
{% set url = alias(site.baseUrl) %}
{% endif %}
<li class="c-nav__item{% if site.id == currentSite.id %} is-current{% endif %}">
<a href="{{ url }}">{{ site.name }}</a>
{% set locale = craft.app.i18n.getLocaleById(site.language) %}
<li class="c-nav__item">
<a href="{{ url(url) }}"{% if (site.id == currentSite.id) %} aria-current="page"{% endif %}>{{ locale.displayName }}</a>
</li>
{% endfor %}
</ul>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment