8

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!

Kitsune
  • 333
  • 2
  • 10

2 Answers2

10

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 %}
Douglas McDonald
  • 13,457
  • 24
  • 57
  • 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 04:55
2

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