To set a button for changing language on the website

hey guys,
i have already set up my pages in the panel in german and english and i can open them but i need a button in the header on the website for changing the language … how can i do that ?

ps.: iam using a snippet-header , so i have several pages like a homepage, about-page, jobs-page ,…

There are examples to switch languages in the docs.


how could i put this code in a if-statement, so that we have only a button (eng or german) which we can press and it changes the language

         <div class="languages">
                 <?php foreach($site->languages() as $language): ?>
                <li<?php e($site->language() == $language, ' class="active"') ?>>
                  <a href="<?php echo $page->url($language->code()) ?>">
                   <?php echo html($language->name()) ?>
                <?php endforeach ?>

like in the following pic …

That would be something like this:

<div class="language">
  <?php if($site->language()->code() == 'en'): ?>
    <a href="<?php echo $page->url('de') ?>">DE</a>
  <?php else: ?>
    <a href="<?php echo $page->url('en') ?>">EN</a>
  <?php endif ?>
1 Like

thaaank you for ur help :smile: