Always use default() filter with random function()

Created on 9 August 2023, 11 months ago
Updated 17 August 2023, 10 months ago

Problem/Motivation

We are using random() Twig function to generate IDs:

  • sometimes it's the default value of a prop (carousel_id, item_id, id...): {{ carousel_id|default("carousel-" ~ random() ) }} and it's OK, nothing to say
  • sometimes it's used directly carousel-{{ random() }} and it makes unit testing impossible because it generates a different template each time when we have the same input slots & props.

With UI Patterns, we don't do these unit tests yet (from preview data) but we shouldn't make them impossible.

Remaining tasks

TODO for each:

  1. Add a new prop fo the id
  2. Use default() filter

For BS4:

pattern-carousel.html.twig:{% set id = 'carousel-' ~ random(1000) %}

Let's push the commit directly in the branch

For BS5:

pattern-accordion-item.html.twig:{% set accordion_item_id = "accordion-item-" ~ random() %}
pattern-accordion.html.twig:{% set accordion_id = "accordion-" ~ random() %}

Let's do a MR

API changes

yes, but is safe

πŸ“Œ 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.69.0 2024