Jump to content

How to get override label for fields


JayGee
 Share

Recommended Posts

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

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?

  • Thanks 1
Link to comment
Share on other sites

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

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:

Image 2018-06-07 at 3.06.07 pm.png

Note: The field names display correctly for fields using their default names - it's just the overridden ones that don't work.

Edited by Guy Incognito
more detail added.
Link to comment
Share on other sites

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

 

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

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

  • 2 years later...

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!")

  • Like 3
Link to comment
Share on other sites

  • 2 years later...

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