site_settings in twig when media outputs entity ID only

Created on 26 July 2023, 11 months ago

Problem/Motivation

When using site_settings in twig and the field is a media image, you only can access the entity ID. There is no render array available.

Steps to reproduce

Render an image in a twig file from site_settings with a media image field 'field_image'.

{% for site_setting in site_settings.your_settings_group.your_setting_name %}
  {{ site_setting.field_image}}
{% endfor %}

Proposed resolution

Provide the render array for the media entity referenced.

✨ Feature request
Status

Closed: works as designed

Version

1.20

Component

Code

Created by

πŸ‡§πŸ‡ͺBelgium johanvdr

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @johanvdr
  • Status changed to Closed: works as designed 11 months ago
  • πŸ‡¬πŸ‡§United Kingdom scott_euser

    With the current Renderer, the easiest way to handle this is to use something like Twig Tweak to render the entity from the ID https://www.drupal.org/docs/contributed-modules/twig-tweak-2x/cheat-shee... β†’

    I suppose the bigger goal here is to actually use the Manage Display as a Renderer option rather than the minimal rendering currently done. That would also mean not auto-loading it into every template as we would add too much overhead. If we do that I would imagine it being a separate bigger issue, so I'll mark this as closed.

    Hope that helps!

  • πŸ‡§πŸ‡ͺBelgium johanvdr

    Indeed, it needs to be in the end using the manage Display (of the field) as a Renderer option.

    For now, I will resort to using twig tweak
    {{ drupal_entity('site_setting_entity', enitity_id) }}

Production build 0.69.0 2024