Hi,
I have a multi language setup with German + English, where German is the default language.
When I add a custom field in the German content file, like
MyFieldName : Some text
and in the template:
$text = $page->MyFieldName()
$text returns “Some text”, which is correct.
However, when I switch to English, and the English content file has no such field, $text also will return “Some text” taken from the German content file.
Likewise, the $page->content()->has($field) function returns true when switched to English, although only the German content file has this field.
Is this intended? I would expect an empty string rsp. “false” returned.
Yes that’s what I meant only instead of hardcoding it, you can use the current language code: $page->content($site->language()->code())->has($field)
There’s also a very useful piece of code that you can use to redirect the user to an error page if the content doesn’t exist. This is used in the docs in a language switch: