How To Return Only Articles That Has Translations Inside Twig Template, Rainlab.Translate Module

- 1 answer

I am using rainlab.translate plugin in my website and have two languages en and ka (English and Georgian Languages).

Also I have Article Model which has some $translatable fields (like title).

Some of my Articles are only in Georgian language, and I do not want to show them in English version once I switch the language.

So what I am trying to do is:

{% for article in articles %}
   {% if article.lang(activeLocale).title %}
      // Then Display Article
   {% endif %}
{% endfor %}

but this does not work as by default if article.title does not have translation it returns default string.

Is there any solution to do this on Twig Template?




I just did one solution which works but if you have any other you are welcome :)

{% for post in articles %}
   {% set post = post.noFallbackLocale.lang(activeLocale) %}

   {% if post.title %}
       // then display post
{% endfor %}