Skip to content

Custom column title on entry index pages #12032

Answered by brandonkelly
mihob asked this question in Q&A
Discussion options

You must be logged in to vote

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:

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';
    }
);

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by brandonkelly
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants