isNotEmpty() for non-existing text file (fallback language in blog post issue)

Hi there,
I am still playing around with showing fallback content for not translated pages. In my article.php template, the first line is:

<?php if($page->text()->isNotEmpty()): ?>

After that, there is a lot of content stuff, then

<?php else: ?>
Fallback text.
<?php endif ?>

The problem now is: The fallback text is not displayed for the German URL, although there is no German text file. The English content (default lang) is displayed instead. There is only article.en.txt in content.

I expected that the German text is empty, so the fallback content would be displayed.

Another thing I tried:
I used isTranslated(), but for the default language it is always true, I can’t use it. Because I will have German-only posts in my blog.

Any ideas?
Thanks and best –Martin

The standard behavior of Kirby is to use the contents of the default language if no translated content exist. So

<?php if($page->text()->isNotEmpty()) ?>

will return true.

What you would have to do, is to check first if the file exists and then check if the field is empty or not, as I suggested in the other thread.

<?php if($page->content(site()->language()->code())->exists() && $page->text()->isNotEmpty()): ?>
1 Like

Thanks, I added the colon:

<?php if($page->content(site()->language()->code())->exists() && $page->text()->isNotEmpty()): ?>

1 Like