Jump to content

$pages->get() does not work properly with multi-language home page

Recommended Posts

Hi, I am currently using Processwire for a client project and am quite pleased with the ease of use and versatility.

Unfortunately I came across a problem I am not able to solve:

I have a multi-lang site where the home page path are as follows:
www.example.com/ -> german (default)
www.example.com/en/ -> english

I build a language switcher that first gets the current page and then displays links for the page in all the different languages.

<?php namespace ProcessWire; ?>
<ul class="lang-switcher">
$real_page = $pages->get($_SERVER['REQUEST_URI']);

foreach ($languages as $language) {
	if (!$real_page->viewable($language)) {
	// echo <li>...</li>

(I need to search for the real page because the language switcher is loaded inside of the menu which is an additional page/template which get loaded via

echo $pages->get("title='Main menu'")->render();

. When using $page->localURL() I get the /main-menu page.)

this works without problems for urls:

But not for:

I diagnosed that $pages->get("/en/") returns a NullPage instead of the english home page.

Do you have any idea why this is and how to fix it.

Thanks alot.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...