Jump to content

How to output overwritten field labels in site template


Juergen
 Share

Recommended Posts

Hello at all

I have overwritten the label of the body field in various templates, but if I try to output it in the site template I always get the initially label name.

The output code:

<?php echo $page->fields->get('body')->label;?>

The initially label of my body field is "maintext" and this will be outputed. In my teammember template I have overwritten "maintext" with "About me" but I always get "maintext" as the label and not "About me".

Can someone point me into the right direction of outputting the overwritten label?

Link to comment
Share on other sites

This gets you the label in the context of the entered template.

$templates->get("template_name")->fieldgroup->getField('body', true)->label;

You could also do this to get for the template of the current page:

$templates->get($page->template->name)->fieldgroup->getField('body', true)->label;
  • Like 7
Link to comment
Share on other sites

  • 1 year later...

Thank you Adrian, and thanks Juergen for asking, so I just got an answer already haha :D
 
By the way, when you got languages enabled it could be interesting to use

$field->getLabel()

instead. It'll always gives you the label in the current language or you can pass the desired language as parameter like e.g.

$field->getLabel($languages->get("de"))

@Ryan, maybe it could be nice to have a second parameter here like true/false to get the default label or the context label?

Link to comment
Share on other sites

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