Add Empty Check Helpers

Created on 10 March 2022, about 3 years ago
Updated 31 January 2025, 3 months ago

Empty checks in Twig are currently a patchwork nightmare, see:
#2547559: Checking for empty fields in Twig templates is complicated
and
🌱 [meta] Themes improperly check renderable arrays when determining visibility Needs work

I guess themers will wait for a stable core solution about +5 years - no offense, just realism.

So i would love to see helper functions in Twig Tweak, based on the results people have posted in the both issues.
This way we will have a centralized best practise solution instead of thousands of themers who spread different empty checks across template files.

IMO the most important checks are for fields (especially fields which come from the entity and not from the render array, eg. node.field_image) and regions.

Feature request
Status

Closed: won't fix

Version

3.0

Component

Code

Created by

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024