1

Is it possible to change the display of the related entries field, to include extra info (hoping to add thumbnail, because otherwise these entries are damn hard to identify!)

I don't think they are quite the same as a standard table view and therefore hookable by defineAdditionalEntryTableAttributes Or can you override the normal view of the field type?

enter image description here

2

Easy task: you can create your own relations field and use that instead. Take a look at the default Entries field here is the php code for it click

All you have to do is changing the template that should be rendered so you'll end up with something like

class MyCustomRelationField extends BaseRelationField
{
    // Static
    // =========================================================================
    /**
     * @inheritdoc
     */
    public static function displayName(): string
    {
        return Craft::t('app', 'My awesome field');
    }
    /**
     * @inheritdoc
     */
    protected static function elementType(): string
    {
        return Entry::class;
    }
    /**
     * @inheritdoc
     */
    public static function defaultSelectionLabel(): string
    {
        return Craft::t('app', 'Add an entry');
    }

    /**
     * @var string Template to use for field rendering
     */
    protected $inputTemplate = 'path/to/your/custom/template';
}

the $inputTemplate is the template that gets rendered in the cp so you'll take the default one here as your base and change the parts you need

<div class="elements">
    {% for element in elements %}
        {% include "_elements/element" with {
            context: 'field',
            size: (viewMode == 'large' ? 'large' : 'small')
        } %}
    {% endfor %}
</div>

to something you like. Because the default content in this include is generated here. Take that as a reference what you have to change/include in your own template (or hook) together with your icon/thumbnail

| improve this answer | |
  • Thanks so much for such a detailed answer Robin! The {% include "_elements/element" %} lead me to a hook which I wasn't sure whether was overrideable, but I could easily add the necessary tweaks within my main template file, using element.img... and a bit of extra CSS – Toby Stokes Jan 13 '18 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.