Add Twig filter to use first non-empty input

Created on 20 March 2023, over 1 year ago

Problem/Motivation

It would be handy to have a filter to, especially since πŸ› Fallback image file path functionality is a security risk Fixed is removing a hardcoded fallback path.

One can already stop on the first of several alternative outputs using Twig operators, but it requires repeating potentially lengthy arguments:

{{ source1|media_image('style', 'class', { 'data-attr': 'foo' }) ?: source2|media_image('style', 'class', { 'data-attr': 'foo' }) }}

Proposed resolution

Add a Twig filter called something like media_first_nonempty to return the first non-empty value in an array.

Example usage:

{{ [source1, source2]|media_first_nonempty|media_image('style', 'class', { 'data-attr': 'foo' }) }}

✨ Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bvoynick

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

Comments & Activities

Production build 0.71.5 2024