Skip to content

Simplify inline conditions with ?? operator #389

@ruudk

Description

@ruudk

Would it be possible to do some optimizations like replacing:

{{ user and user.locationCountry.value ?? '' }}

and change it to

{{ user.locationCountry.value ?? '' }}

The initial code was written because user can be null and it's chaining multiple levels deep is not expected to work.

But the ?? operator in Twig takes care of this already.

{{ blaat.test.something.else.whatever ?? '' }}

is perfectly valid.

Twig Playground

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions