Jump to content

Recommended Posts

Posted

I try to re-use fields and would like to display the field label on the frontend, but all I got is the default label, not the overriden one.

It's a multilanguage site but I don't think it matters.

This is what I've tried:

echo $page->fields->body->label;
echo $templates->get('package')->fields->body->label;

Is there a way to get the overriden label text?

Posted (edited)

You need to get in in context

$p = $pages->get(1040);
$label = $p->fields->get('body', true);
echo $label;

// or if you are sure the page is there, a one-liner
echo $pages->get(1040)->fields->get('body', true);

 
Edit: I could have sworn @LostKobrakai was asleep :-)  :P .  Beaten, again :-)

Edited by kongondo
  • Like 2
Posted

Edit: I could have sworn @LostKobrakai was asleep :-)  :P .  Beaten, again :-)

Asleep in the midst of the day? There's probably only 1h time difference to your location.

Posted

Thanks guys, could've asked earlier to save some time :)

Finally I settled with this:

$templates->get('package')->fields->getFieldContext('body')->$labelLang

Where $labelLang is 'label' + language ID (if it's not the default language, otherwise simply 'label').

Posted

Asleep in the midst of the day? There's probably only 1h time difference to your location.

Yeah...the question went unanswered for a whole 1 minute, which means you were either asleep or busy,  :lol: ...just kidding... :-X

  • 3 years later...
Posted

Had this same issue today, ie get the customised label for a page/template field and tried all the above. They all returned the original field label and couldn't find any reference to the 'true' option when getting 'fields' or 'field' in the API Docs. Maybe PW has moved on or more likely, I missed something. Anyway, what did work for me was:

$page->getField("body")->label;

https://processwire.com/api/ref/page/get-field/

 

  • Like 4
  • 5 years later...
Posted

Hi,

This one worked for me in a multi-language field:

$string = $page->getField('your_field')->getLabel();

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