Component CS: ternary operator

Created on 13 February 2025, about 2 months ago

Problem/Motivation

Creating an issue to follow Slack discussion.

https://git.drupalcode.org/project/ui_suite_bootstrap/-/jobs/4321216 detected that, https://git.drupalcode.org/project/ui_suite_bootstrap/-/blob/5.1.x/compo... is problematic:

...
{% set header_length = header ? header|length : 0 %}
...

More context:

...
{% set header_length = header ? header|length : 0 %}
{% set header_columns = header_columns|default(header_length) %}
...

SDC Devel error?

Proposed resolution

?

📌 Task
Status

Active

Version

5.1

Component

Code

Created by

🇫🇷France Grimreaper France 🇫🇷

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

Comments & Activities

  • Issue created by @Grimreaper
  • 🇫🇷France pdureau Paris

    it may be an sdc_devel error

    it is normal for {% set header_length = header|length ? header : 0 %} to be converted into {% set header_length = header ?: 0 %} by Twig when loading as an AST and analysed by sdc_devel

    But i don't understand why it is the case for {% set header_length = header ? header|length : 0 %}

  • 🇫🇷France pdureau Paris

    Grimreaper, I don't reproduce in local. Do you? if yes, what is your setup? How different it si from drupal.org CI?

  • 🇫🇷France Grimreaper France 🇫🇷

    The problem occurred on Twig 3.16.0, but no more on Twig 3.19.0

Production build 0.71.5 2024