Jump to content

Accessing custom templates field for languages (system) template?


Gadgetto
 Share

Recommended Posts

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

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