6

I'm trying to get the locale title (dutch: nl_nl) of an entry, in the english version of the same post. I want to do this so that on hover it shows the English title's Dutch version.

Any help is appreciated!

8

You can use the 'locale' and 'id' attributes in your query to request the same entry in another locale.

{{ entry.title }}<br>
{{ craft.entries.id([entry.id]).locale('nl_nl').first.title }}

Update. If there is any chance that the entry/section is disabled for that locale you can also check it first, like so.

{% set nlEntry = craft.entries.id([entry.id]).locale('nl_nl').first %}
{% if nlEntry %}
    {{ nlEntry.title }}
{% endif %}
| improve this answer | |
  • Had no idea i could use a twig command like this. It worked like a charm, thanks! – Kitsune May 11 '15 at 20:09
  • 1
    Glad it worked. Btw... I thought I should add — to be safe you might also want to check to make sure the entry is enabled for the other locale. I added an example. – Douglas McDonald May 12 '15 at 4:55
1

Thx, this is how I used it to get the titles of all events in the current language:

{% set locale = craft.i18n.getCurrentLocale() %}
{% set events = craft.entries.section('events').level(1).locale(locale) %}
{% for event in events %}
    <p>{{ event.title }}</p
{% endfor %}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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