Custom column title on entry index pages #12032
-
As an example, I have a field titled "General Text Field" that I want to use with multiple entries. Now I use the field in entry A and name it "Heading". If you now select the field on the index page of entry A, the title of the column will be "General Text Field" and not "Heading". This is quite confusing for the editor. Is there any way to adjust this or rename column titles? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Craft doesn’t use the custom field labels because the same field could be used by multiple field layouts, each with their own label overrides. You can customize the table heading from a module though, using the use craft\events\DefineSourceTableAttributesEvent;
use craft\services\ElementSources;
use yii\base\Event;
Event::on(
ElementSources::class,
ElementSources::EVENT_DEFINE_SOURCE_TABLE_ATTRIBUTES,
function (DefineSourceTableAttributesEvent $event) {
$field = Craft::$app->fields->getFieldByHandle('myTextFieldHandle');
$event->attributes["field:$field->uid"]['label'] = 'Heading';
}
); |
Beta Was this translation helpful? Give feedback.
Craft doesn’t use the custom field labels because the same field could be used by multiple field layouts, each with their own label overrides.
You can customize the table heading from a module though, using the
EVENT_DEFINE_SOURCE_TABLE_ATTRIBUTES
event: