{{ switch }} continues across nested loops when the inner count is odd
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 72/100
Línea de trabajo
El error está en la clase de la etiqueta Rotate, que guarda su posición en un array estático $counts indexado únicamente por un hash md5 de los parámetros de la etiqueta. Empieza reproduciendo el problema con la plantilla de bucles anidados del issue y revisa cómo se construye y se reinicia ese hash. Se considera terminado cuando cada bucle interno vuelve a empezar en el primer valor, con una prueba que cubra bucles anidados con un número impar de iteraciones internas.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Bug description
{{ switch }} tag does not restart at the beginning of each inner loop when it is rendered inside a nested loop.
The counter is shared for the whole request.
How to reproduce
With two values,
an odd inner loop makes the next parent item continue the previous sequence.
An even inner loop hides the problem, because the sequence lands back on the first value.
Steps to reproduce
{{ loop times="2" }}
{{ loop times="3" }}
{{ switch between="1|0" }}
{{ /loop }}
{{ /loop }}
Expected
Each inner loop starts again at the first value.
1 0 1
1 0 1
Actual
1 0 1
0 1 0
The second group is the continuation of the first (… 1 then 0 1 0), not a new 1 0 1.
Logs
Environment
Environment
Laravel Version: 12.70.2
PHP Version: 8.4.16
Composer Version: 2.10.2
Environment: local
Debug Mode: ENABLED
Maintenance Mode: OFF
Timezone: UTC
Locale: fr_CA
Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED
Drivers
Broadcasting: log
Cache: file
Database: sqlite
Logs: stack / single
Mail: smtp
Queue: sync
Session: file
Storage
public/storage: NOT LINKED
Statamic
Addons: 2
License Key: Not set
Sites: 2 (Français, English)
Stache Watcher: Disabled
Static Caching: Disabled
Version: 6.40.0 PRO
Statamic Addons
jacksleight/statamic-bard-texstyle: 4.2.3
mg/litespeed: dev-dev
Installation
Fresh statamic/statamic site via CLI
Additional details
Cause
Statamic\Tags\Rotate stores the position on a static array, keyed only by a hash of the tag parameters:
protected static $counts = [];
$hash = md5(implode(',', $this->params->all()));
if (! isset(static::$counts[$hash])) {
static::$counts[$hash] = 0;
}
$switch = $vars[static::$counts[$hash] % count($vars)];
static::$counts[$hash]++;
resetStaticState() clears that array between requests. Nothing clears it between iterations of the parent loop, and the hash does not include the parent iteration. Every render of the same {{ switch }} shares one counter.
A parameter such as for="gallery" does not scope the counter to a loop. It is only part of the hash, so it separates this tag from another {{ switch }} with different parameters.
- Lenguaje dominante
- PHP
- Estrellas
- 4.9k
- Forks
- 647
- Merge medio
- 23 h 42 min
- PR fusionados (30 d)
- 148
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de statamic/cms
-
accessibility
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
antlers
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
Los mantenedores suelen responder en 1 día
-
antlers modifiers
Dificultad 2/5 1-3 horas Aptitud para principiantes 57/100
statamic/cms#15832 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Multisite: switching site in the collection listing opens a different entry, not the localizationAbiertomultisite
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
Los mantenedores suelen responder en 1 día
-
Select field preview disappears after reordering Replicator setsPosiblemente ocupada @lazerg la tomó hace 4 días. Abiertofieldtypes
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
Los mantenedores suelen responder en 1 día
Todos los issues de statamic/cms
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
nikic/PHP-Parser#1187 ·
-
15.0
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
needs-triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Icinga/icinga-notifications-web#645 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
OpenMage/magento-lts#5865 ·
Los mantenedores suelen responder en 3 días