shakogele
shakogele

Reputation: 399

How to return only articles that has translations inside Twig template, Rainlab.Translate module

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?

Thanks

Upvotes: 1

Views: 217

Answers (1)

shakogele
shakogele

Reputation: 399

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
   {%endif%}
{% endfor %}

Upvotes: 2

Related Questions