Prevent Default Language

Hello,

I am building a webpage where the English version sometimes is not equal to the German (default) version.

For example: I have a page with a ‘description’ textarea and a ‘goals’ textarea. When I only have a ‘description’ in the English version, but there is a ‘goals’ in the German version, the English ‘description’ and the German ‘goals’ is shown (when English is selected as language).

Is there a way to only get the English ‘description’ in such a case?

1 Like

You can either filter pages by language using a custom filter, e.g.

$articles = $page->children()->visible()->filter(function($child) {
     return site()->language()->code() == $child->language()->code();
});

http://forum.getkirby.com/t/how-to-avoid-automatic-fallback-for-translations/1705

or in case of a single page:

page('mypage')->content('en');

(use an if statement to check for $site->language()->code() and a variable, of course, instead of hard-coding the language)

Thank’s for the great answer! But I think I need something a little bit different. Is there something like:

  if (site()->language()->code() == $page->description()->language()->code()) {..}

The second part does not return any language code here.

I don’t think this is necessary, because you can use my suggestion above and do sth. like this:

 <?php 
$lang = $site->language()->code();
echo $page->content($lang)->text()->kirbytext();
 ?>

Then Kirby will only fetch the content of the field that exists in the corresponding language.

1 Like

Ah, now I got it! Thank you so much, it works perfectly! :slight_smile: