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 %}

1 Answer 1

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?

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.