Multi language blog

I have an article only in dutch but when I am on the English page It shows the dutch article instead of showing nothing.
Anybody nows how to solve this?

This is the default Kirby behavior, it falls back to the default language if content in the non-default languages is missing. If you only want to show content that is available in a language, you can use an if statement to check if content in that language is available:

$code = $site->language()->code();
if($page->content($code)) {
  // output your content
}

It doesn’t work it still shows the default language article.

Oh and you forget a ) after ($code) in your code above

Then try:

<?php
$code = $site->language()->code();
 if($page->content($code)->exists()):
  // do something
  }
 ?>

Let me know if this works. However, this will only work if the content file of the non-default language does not exist, of course. Otherwise, if the file exists but the content is empty, you will need an additional check.

It works thanks a lot. but how does the check work if the file exists and the content is empty?

Then you’ll have to do this on a per field basis:

<?php
$code = $site->language()->code();
if($page->content($code)->exists() && $page->field()->isNotEmpty()):
  // do something
}
?>

Or you can use isTranslated()

<?php if($page->description()->isTranslated()): ?>
  <?php echo $page->description()->kirbytext() ?>
<?php endif ?>
1 Like

Do I need to specify a field ?

Yes, as I said, if the language specific file exists, you have to do your checks on a per field basis.

Edit: But non-default language files are not created by default. If you don’t want any articles created in a non-default language, you can prevent this using permissions.

It works thanks a lot.

Fine, please see my edit of the last post.