Jump to content

Retrofitting beginner profile with multi-language


Neo
 Share

Recommended Posts

I have a site that was developed on ProcessWire 3 using the "beginner profile" with direct output.

Requirements got changed during development and the site now needs to be multi-language.

For that I installed the 4 available language modules in the backend:

- Language Support (Fields, Page Names, Tabs)

I then added the language switcher from the multi-language profile from _main.php to _head.php:

<!-- language switcher / navigation -->
    <ul class='languages'><?php
        foreach($languages as $language) {
            if(!$page->viewable($language)) continue; // is page viewable in this language?
            if($language->id == $user->language->id) {
                echo "<li class='current'>";
            } else {
                echo "<li>";
            }
            $url = $page->localUrl($language); 
            $hreflang = $homepage->getLanguageValue($language, 'name'); 
            echo "<a hreflang='$hreflang' href='$url'>$language->title</a></li>";
        }
    ?></ul>

 

Unfortunately, that throws the following error:

Error: Call to a member function getLanguageValue() on null 

 

I assume that the function getLanguageValue() is not available, although all available modules have been installed.

Any idea how to fix this?

 

Link to comment
Share on other sites

The error is saying that the function is available, but what it is being called on is not - ie $homepage

So you can either define $homepage like:

$homepage = $pages->get("/");

or you can do:

$hreflang = $pages->get("/")->getLanguageValue($language, 'name');

if you don't need $homepage anywhere else.

  • Like 2
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
 Share

  • Recently Browsing   0 members

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