tpr Posted January 27, 2016 Share Posted January 27, 2016 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? Link to comment Share on other sites More sharing options...
LostKobrakai Posted January 27, 2016 Share Posted January 27, 2016 $templates->get("package")->fields->getField("body", true); $templates->get("package")->fields->getFieldContext("body"); 2 Link to comment Share on other sites More sharing options...
kongondo Posted January 27, 2016 Share Posted January 27, 2016 (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 . Beaten, again Edited January 27, 2016 by kongondo 2 Link to comment Share on other sites More sharing options...
LostKobrakai Posted January 27, 2016 Share Posted January 27, 2016 Edit: I could have sworn @LostKobrakai was asleep . Beaten, again Asleep in the midst of the day? There's probably only 1h time difference to your location. Link to comment Share on other sites More sharing options...
tpr Posted January 27, 2016 Author Share Posted January 27, 2016 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'). Link to comment Share on other sites More sharing options...
kongondo Posted January 27, 2016 Share Posted January 27, 2016 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, ...just kidding... Link to comment Share on other sites More sharing options...
psy Posted September 25, 2019 Share Posted September 25, 2019 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/ 3 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