0

I have two languages (German and French).
In my sections I have German enabled as default language. French is off by default.

My Problem is: I always want to show content, even if the other language is disabled and, when an entry is not translated yet, show a note like "Entry not translated yet."

I know about localeEnabled and status and I can query the following way:

{% set entries = craft.entries.section('referenzen').localeEnabled(false).status(null).find() %}

That outputs all of the entries.
But I am running into problems with the "_entry" template.

And I don't really know how to differentiate between entries that have their status turned off vs. entries that only have a language turned off.

Does anybody have a solution to this problem?

Cheers
Stefan

2 Answers 2

1

So thanks to Brad I found this solution:

{# Get all entries regardless if the locale is enabled or not #}
{% set allEntries = craft.entries.section('yourSection').status(null).localeEnabled(false).find() %}

{# Set the other locale (could be done differently, but since I have only two, I chose the easy way) #}
{% if craft.locale == 'de' %}{% set otherLocale = 'fr' %}{% else %}{% set otherLocale = 'de' %}{% endif %}

{# Get all entries that are not disabled regardless if the locale is enabled or not #}
{% for entry in allEntries if entry.enabled == 1 %}

    {# if the locale is turned off, search for the entry in the other language #}
    {% if entry.status == 'disabled' and entry.localeEnabled == 0 %}

        {# Get the same entry in the other locale #}
        {% set otherEntry = craft.entries.id(entry.id).locale(otherLocale).first() %}

        <h2><a href="{{ otherEntry.url }}">{{ otherEntry.title }} ({{ otherLocale|upper }})</a></h2>

    {% else %}
        <h2><a href="{{ entry.url }}">{{ entry.title }}</a></h2>
    {% endif %}

{# else (for the loop) all the entries are disabled #}
{% else %}
    <p>No results</p>
{% endfor %}

It works great for my case.

1
  • Glad you got it sorted!
    – Brad Bell
    Sep 22, 2015 at 19:16
0

From your template you can check if the entry is enabled via entry.enabled.

If an entry's locale is set to disabled (either via being disabled by default in the section's settings or manually on an entry), then the overall entry's status will be disabled as well.

If, for whatever reason, you need to see all of the locales for an entry and their enabledByDefault status, you can do something like:

<ul>
    {% for key, value in entry.getLocales() %}
        <li>locale = {{ key }}, enabledByDefault = {{ value['enabledByDefault'] }}
    {% endfor %}
</ul>
2
  • Thanks a lot brad, my brain mixed up {{ entry.enabled }} and {{ entry.status }}. So {{ entry.status }} is 0 if {{ entry.localeEnabled }} is 0 OR {{ entry.enabled }} is 0. This is perfect! Thanks!
    – outline4
    Sep 22, 2015 at 8:50
  • I am trying to do the following: {% set entries = craft.entries.section('referenzen').status(null).localeEnabled(false).enabled('1‌​').find() %} but the enabled('1') part doesn't work. Do I have to do it differently?
    – outline4
    Sep 22, 2015 at 10:12

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.