Jump to content

Recommended Posts

Posted

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

Posted

@Gadgetto 

foreach ($languages as $language) {
	...
	// $hreflang = $page->getLanguageValue($language, 'languagecode');
	$hreflang = $language->getLanguageValue($language, 'languagecode');
	...
}

 

Posted

@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...

 

Posted

@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. 

  • Like 2

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
  • Recently Browsing   0 members

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