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!
Craft CMS Stack Exchange is a question and answer site for administrators, end users, developers and designers for Craft CMS. It only takes a minute to sign up.
Sign up to join this communityI'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!
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 %}
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 %}