JayGee Posted June 7, 2018 Share Posted June 7, 2018 I've overridden the name of the some fields on a template, but I can't seem to output the updated names on the front end. PW outputs their original names regardless of what is being displayed in the template editor. Is this correct behaviour? Currently looping through to get fields outputting each as follows: echo '<input type="text" name="'.$field['name'].'" class="form-control" id="'.$field['name'].'" placeholder="'.$field['label'].'">'; When I dump my $field object there doesn't seem to be any output for the overridden labels in the array, is there another way to do this? Link to comment Share on other sites More sharing options...
louisstephens Posted June 7, 2018 Share Posted June 7, 2018 Not to sure how the rest of your template is set up, but I have found that the following does work. $page->getField('body')->label; Are you using the label in the template corresponding to the actual page, or are you pulling in the label in another template? 1 Link to comment Share on other sites More sharing options...
JayGee Posted June 7, 2018 Author Share Posted June 7, 2018 6 minutes ago, louisstephens said: Not to sure how the rest of your template is set up, but I have found that the following does work. $page->getField('body')->label; Are you using the label in the template corresponding to the actual page, or are you pulling in the label in another template? I'm pulling all the fields from a template type, in this particular instance 'dog'. I'm getting all the template fields by: $t = $templates->get("dog"); $dogFields = $t->fields; The looping through my $dogFields object to output the fields as per snipper earlier. I have overridden the 'title' field in this template to be called 'dog name' as it just makes more sense in this context, but I can only ever seem to output the field's original default name 'title'. Obviously I don't want to rename the title field globally. Link to comment Share on other sites More sharing options...
dragan Posted June 7, 2018 Share Posted June 7, 2018 Perhaps you'll find a solution here: Link to comment Share on other sites More sharing options...
JayGee Posted June 7, 2018 Author Share Posted June 7, 2018 (edited) Thanks @dragan - but no luck with the methods in that thread either. Just to reiterate, I'm not having any problems displaying the labels. It's just that the labels being output by PW are the default field labels set in the global field editor, not the override labels applied to those fields in the template editing interface. See screen grab: Note: The field names display correctly for fields using their default names - it's just the overridden ones that don't work. Edited June 7, 2018 by Guy Incognito more detail added. Link to comment Share on other sites More sharing options...
dragan Posted June 7, 2018 Share Posted June 7, 2018 It works here. Did you try this? $label = $templates->get("employee")->fieldgroup->getField('body', true)->label; echo $label; // displays "Zusätzliche Informationen" instead of the default "WYSIWYG Editor" label = tpl override 2 1 Link to comment Share on other sites More sharing options...
JayGee Posted June 7, 2018 Author Share Posted June 7, 2018 6 minutes ago, dragan said: It works here. Did you try this? $label = $templates->get("employee")->fieldgroup->getField('body', true)->label; echo $label; // displays "Zusätzliche Informationen" instead of the default "WYSIWYG Editor" label = tpl override Ah perfect - yes can confirm works as follows: echo $templates->get('dog')->fieldgroup->getField($field['name'], true)->label; New it would be available somehow - Thanks for your help ?. Link to comment Share on other sites More sharing options...
ottogal Posted June 7, 2018 Share Posted June 7, 2018 About the distinction between a template and its fieldgroup you can read in the API Documentation: See the last section "Using Templates and Fields from the API" from http://processwire.com/api/variables/templates/. Link to comment Share on other sites More sharing options...
2hoch11 Posted July 8, 2020 Share Posted July 8, 2020 Just in case somebody needs to get the override label in the current language… I did… // Get label in current language echo $templates->get('template_name')->fieldgroup->getField('my_field_mame', true)->getLabel(); // OR directly from the page (no matter how the templates name is): echo $page->template->fieldgroup->getField('my_field_mame', true)->getLabel(); This is a way faster than using translate stings in the template: __("I'm an in english headline, translate me!") 3 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted August 3, 2022 Share Posted August 3, 2022 $page->fields->getField('my_field_mame', true)->getLabel() This also works and is a bit shorter. 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