Support removing nested elements in Twig 'without' filter

Created on 29 January 2019, about 6 years ago
Updated 24 April 2025, about 8 hours ago

Problem/Motivation

Currently the without Twig filter doesn't allow specifying nested keys to exclude.

Proposed resolution

We can't just update without to accept an array for a nested key, because it's already been updated to accept arrays and assume they're just sequences of base-level keys in #3093577: Let Twig without() filter take both arrays and strings as arguments .
We could

  • use a delimiter character (patch in #14 Support removing nested elements in Twig 'without' filter Needs work ): if present, the code would interpret them as nested keys? E.g.:
    {{ content|without('parent.child1', 'parent.child3') }}
    If '.' is a legit character in existing keys (I don't believe it is), we could find something else that's safe. E.g. '/' or whatever.

    Or we could use the wonky array syntax at the end of #5 Support removing nested elements in Twig 'without' filter Needs work and use '][' or equivalent.

  • use a different filter for recursive values (without_nested anyone?)
  • deprecate the current array behavior of without and add nested value support to D10.

Remaining tasks

Decide if it's safe to use a delimiter character, and if so which one. It looks like menu-local-tasks.html.twig for example can have periods in key names.

User interface changes

API changes

Data model changes

Release notes snippet

Original report by @taote

Under Drupal 8.6.5, after installing the module Field Layout, the filter function 'without' in the templates for my paragraphs, for example, is ignored. Once uninstalled the filter works fine again.

For example, if I put this in the twig template for a certain paragraph:

{{ content|without('field_label') }}

The field label is shown when the Field Layout module is installed.

Feature request
Status

Needs work

Version

11.0 🔥

Component

theme system

Created by

🇪🇸Spain taote

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