2

Is it possible to retrieve a field value from an alternate locale? I'm working on a multi-language dictionary website and it would be helpful to display values for an entry in more than one locale (language), while the main content stays in the current locale. Right now I have something setup like this:

{% for word in dictionaryWords %}
    {# returns definition for the word in the current locale #}
    <p>{{word.definition}}</p>  
{% endfor %}

I'd like to add a secondary definition in another language from a different locale. Something like this, but I'm not sure how to get at the field data from a different locale.

{% for word in dictionaryWords %}

  {# returns definition for the word in the current locale #}
  <p>{{word.definition}}</p>

  {# returns definition for the word in a secondary locale #}
  {% if currentLanguageID == "languageID1" %}
    <p>{{ word definition in language 2 }}</p>        
  {% elseif currentLanguageID == "languageID2" %}
    <p>{{ word definition in language 1 }}</p>
  {% endif %}

{% endfor %}
3

You can just manually fetch the entry in the other locale. Assuming you already have the first entry, something like:

{% set localeEntry = craft.entries.id(entry.id).locale(languageID1).first() %}

{% if localeEntry %}
    {{ localEntry.otherWordDefinition }}
{% endif %}
  • Brad this worked great. Thanks for your help. – Justin K Apr 26 '16 at 9:46

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.