Jump to content

Multiple trees: set one tree as root


u-nikos
 Share

Recommended Posts

Ryan the localUrl doesnt work if theres 404 thrown for a url. When you call a url that doesnt exist it will stay at that url and renders the 404 page. There it fails because something with the page names language module doesnt have a language set or something I cant remember. I think its maybe also only if not default language or the user has alternative language set. Try that changing user language and see.

Link to comment
Share on other sites

Ryan, is always the localUrl call.

To try it locally:

 

- install the default PW profile

- install all the Language* modules

- add a second language (Italian in my example)

- in head.inc add 

<?php
echo "<ul id='subnav' class='nav'>";

foreach($languages as $language) {
if(!$page->viewable($language)) continue; // check if page not published for this language
$url = wire('page')->localUrl($language);
$title = $language->title;
echo "<li><a href='$url'>$title</a></li>";
}

echo "</ul>";
?>
 

 

Now call:

 

http://pw.dev/

http://pw.dev/it/

http://pw.dev/http404/

http://pw.dev/it/http404/

and there are no problems.. but if you call

 

http://pw.dev/error

http://pw.dev/it/error

 

you can see the error in sidebar.

Obviously if the menu is on the very top of the page you see only a blank page.

Link to comment
Share on other sites

I've pushed an update that fixes this issue: https://github.com/ryancramerdesign/ProcessWire/commit/9e1f46d3d1c69bebbd0415f58baad627a0d194d2

It was also a fairly simple matter to make it identify the language from the URL, when present. So I added that too. Meaning, if something about the URL points to a language (like /it/ at the beginning, for example) then it'll deliver the 404 in Italian rather than the default language. 

  • Like 2
Link to comment
Share on other sites

Thanks Ryan, it works well. :)

In your opinion, make sense rewrite url in switch language menu when it deliver the 404 error page?

$url = (wire('page')->template != 'notfound') ? wire('page')->localUrl($language) : wire('pages')->get('/')->localUrl($language);
Link to comment
Share on other sites

I originally missed the issue with language switchers not working on the 404 page because all the instances where I'm using language switchers, I was only have it show the language switcher if the page was not the 404 page. The reasoning there is just that in my case, there wasn't much point in being able to show different language versions of a 404 page. If your situation is similar, I recommend simply not showing the language switcher when on a 404 page. Though if you want the switcher to redirect back to the homepage, that seems like another decent approach. But here's what I did:

if($page->id != $config->http404PageID){
  // render the language switcher
} 
  • Like 2
Link to comment
Share on other sites

  • 1 year later...

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...