Ad
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
Ad
Answer
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 %}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
Ad