Juergen Posted January 31, 2018 Share Posted January 31, 2018 Hello @all, I have tried to output the overridden label from a specific tab inside my template on the frontend. I have used this documentation: https://processwire.com/api/ref/template/get-tab-label/ The tab name is called "tab1" and the labels were overriden with "Kontakt" (German) and "Contact" (English). To output the label depending on the language on the frontend I use the following code snippet: $tablabel = $page->template->getTabLabel('tab1'); echo $tablabel; and $tablabel = $page->template->getTabLabel('tab1', $user->language->id); echo $tablabel; But both versions output only the default (German) tab label. I appreciate your help. Is there something that I am missing? But both version output an empty string, so it seems that the overridden values will not be taken into account. Link to comment Share on other sites More sharing options...
zoeck Posted January 31, 2018 Share Posted January 31, 2018 i think theres a missing comma $tablabel = $page->template->getTabLabel('tab1', $user->language->id); 1 Link to comment Share on other sites More sharing options...
Juergen Posted January 31, 2018 Author Share Posted January 31, 2018 4 minutes ago, zoeck said: i think theres a missing comma Sorry this was only a writing mistake. In the original code the comma is present. Link to comment Share on other sites More sharing options...
zoeck Posted January 31, 2018 Share Posted January 31, 2018 34 minutes ago, Juergen said: Sorry this was only a writing mistake. In the original code the comma is present. Oh, okay When i use "$user->language->id" inside of the "getTabLabel", theres an error (tracy )... You can use it without "->id": $tablabel = $page->template->getTabLabel('tab1', $user->language); i checked it, and it works 1 Link to comment Share on other sites More sharing options...
Juergen Posted January 31, 2018 Author Share Posted January 31, 2018 Strange, in my case it outputs nothing with the same code and Tracy doesnt complain about anything. Link to comment Share on other sites More sharing options...
Juergen Posted January 31, 2018 Author Share Posted January 31, 2018 I use the latest DEV and PHP 7. Just to clearify: My tab field is type of "FieldsetTabOpen". Link to comment Share on other sites More sharing options...
zoeck Posted January 31, 2018 Share Posted January 31, 2018 (edited) Okay, same problem here with the FieldsetTabOpen Field... I just checked it with the default "content" tab of the template... /edit: okay, now i get the Label $tablabel = $page->fields->tab1->getLabel($user->language->id); Edited January 31, 2018 by zoeck Link to comment Share on other sites More sharing options...
BitPoet Posted January 31, 2018 Share Posted January 31, 2018 If tab1 is a FieldsetTabOpen, you need to use $template->fieldgroup->getField('tab1')->getLabel($language); 3 Link to comment Share on other sites More sharing options...
Juergen Posted January 31, 2018 Author Share Posted January 31, 2018 Ok, I ended up with the following codes in site/_init.php //get labels, title, values and descriptions in different languages if ($user->language->name != 'default') { $title = "title{$user->language}"; $value = "value{$user->language}"; $label = "label{$user->language}"; $description = "description{$user->language}"; $notes = "notes{$user->language}"; } else { $title = 'title'; $value = 'value'; $label = 'label'; $description = 'description'; $notes = 'notes'; } and on the page itself: echo $page->template->fields->getFieldContext('tab1')->$label; Pay attention to "$label" instead of "label". The same can be achived by using description, notes,.... 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