Switching languages in the frontend
With multiple available languages, you probably want to provide a way for your users to switch between those languages.
With the $kirby->languages()
method we can fetch all information about available languages. Here are two possible ways to implement such a language switch.
Switch A
The first option is to redirect users to the home page when they select another language. This can be done by using $language->url()
for the link.
Switch B
The second option is to redirect users to the same page in the selected language. This can be done by using $page->url($language->code())
for the link.
Switch C
You can use this third option if you want to redirect the user to the error page or any other page you define, e.g. home or search, in case there is no content available in the target language: