3

Is it possible to loop through locales? For example:

{% locale in craft.locales %}
    {# get link for each locale available #}
    <a href="{{ locale.getUrl }}">{{ locale.title }}</a>
{% endfor %}
cballenar
  • 1,409
  • 11
  • 23

1 Answers1

4

You can try to use the following code to loop through the locales:

{% set locales = craft.i18n.getSiteLocaleIds()%}

{% for locale in locales %}
    {% set localeEntry = craft.entries.id(entry.id).locale(locale).first %}
    <a href="{{ localeEntry.getUrl() }}">{{ localeEntry.title }}</a>
{% endfor %}

A full solution for a language switcher is described under How can I build a language switcher?

Tom Bauer
  • 1,327
  • 7
  • 14