Gadgetto Posted November 3, 2018 Share Posted November 3, 2018 Hello there, I'm very new to Processwire CMS and here is my first question: I've added a custom field to the language system template called languagecode (holds the ISO language code for each language). How can I access this custom field? I tried this for the $languages array: foreach ($languages as $language) { ... $hreflang = $page->getLanguageValue($language, 'languagecode'); ... } but return values are empty. BTW, this works as expected: <html lang="<?php echo $user->language->languagecode; ?>"> Thanks in advance for your help! Martin Link to comment Share on other sites More sharing options...
Zeka Posted November 3, 2018 Share Posted November 3, 2018 @Gadgetto foreach ($languages as $language) { ... // $hreflang = $page->getLanguageValue($language, 'languagecode'); $hreflang = $language->getLanguageValue($language, 'languagecode'); ... } Link to comment Share on other sites More sharing options...
Gadgetto Posted November 3, 2018 Author Share Posted November 3, 2018 @Zeka thanks for the hint, I’ll try this. But the code from my post comes from _main.php template preinstalled with PW and I thought it should work. Hmm... Link to comment Share on other sites More sharing options...
Zeka Posted November 3, 2018 Share Posted November 3, 2018 @Gadgetto foreach ($languages as $language) { ... $hreflang = $page->getLanguageValue($language, 'languagecode'); // ... } As you wrote, you have added 'languagecode' field to language template, but in your snippet, you are trying to get value from 'languagecode' field from $page which, I assume, is using home or basic-page template. This code will work if you add 'languagecode' field to a template which used by the current page. 2 Link to comment Share on other sites More sharing options...
Gadgetto Posted November 3, 2018 Author Share Posted November 3, 2018 OK, thanks - it works now! Have to learn a lot ? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now