Can’t figure out why $page->url($language->code()) won’t work :(

Trying to upgrade from Kirby 2 to 3; this is the only bit that resists me!

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

I get this error.

Call to a member function code() on null

Having a hard time knowing what I should do. Removing all this code makes the site works, but commenting it doesn’t . :thinking: Thanks for the help :wink:

I think you should write:

<?php foreach($kirby->languages() as $language): ?>

guide/languages/switching-languages

2 Likes

AH indeed; everything was so clear on this page! Big thanks for the help :upside_down_face:

1 Like