Offcanvas is not testing the existence of the variant variable

Created on 11 August 2023, over 1 year ago
Updated 17 August 2023, over 1 year ago

Problem/Motivation

Offcanvas is not testing the existence of the variant variable (which may be missing):

{% set variants = variant|split('__')|map(v => v|lower|replace({(v): 'offcanvas-' ~ v})|replace({'_': '-'})) %}
{% set attributes = attributes.addClass(variants) %}

https://git.drupalcode.org/project/ui_suite_bootstrap/-/blob/5.0.x/templ...

Variants:

    start:
      label: "Start"
    end:
      label: "End"
    top:
      label: "Top"
    bottom:
      label: "Bottom"

https://git.drupalcode.org/project/ui_suite_bootstrap/-/blob/5.0.x/templ...

Proposed resolution

Not sure about what to do...

Add the condition?

{% if variant %}
  {% set variants = variant|split('__')|map(v => v|lower|replace({(v): 'offcanvas-' ~ v})|replace({'_': '-'})) %}
  {% set attributes = attributes.addClass(variants) %}
{% endif %}

Add a default value?

  {% set variants = variant|default('start')|split('__')|map(v => v|lower|replace({(v): 'offcanvas-' ~ v})|replace({'_': '-'})) %}
  {% set attributes = attributes.addClass(variants) %}
📌 Task
Status

Fixed

Version

5.0

Component

Code

Created by

🇫🇷France pdureau Paris

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

Comments & Activities

Production build 0.71.5 2024