如何 return 只有在 Twig 模板 Rainlab.Translate 模块中有翻译的文章

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

我在我的网站上使用 rainlab.translate 插件,并且有两种语言 enka(英语和格鲁吉亚语)。

我还有 Article 模型,其中有一些 $translatable 字段(例如 title)。

我的一些文章只有格鲁吉亚语,我不想在切换语言后显示英文版本。

所以我想做的是:

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

但如果 article.title 没有翻译,默认情况下这不起作用 returns 默认字符串。

在 Twig 模板上有什么解决方案吗?

谢谢

我只做了一个可行的解决方案,但如果您有任何其他解决方案,欢迎您:)

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

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