{{ switch }} continues across nested loops when the inner count is odd
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 72/100
Direzione di ricerca
Il bug si trova nella classe del tag Rotate, che mantiene la propria posizione in un array statico $counts indicizzato solo tramite un hash md5 dei parametri del tag. Inizia riproducendo il problema con il template di cicli annidati presente nella issue, quindi leggi come viene costruito e azzerato quell'hash. È completato quando ogni ciclo interno ricomincia dal primo valore, con un test che copra cicli annidati con un numero dispari di iterazioni interne.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- PHP
- Stelle
- 4.9k
- Fork
- 647
- Merge medio
- 23h 42m
- PR unite (30g)
- 148
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di statamic/cms
-
accessibility
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
I maintainer di solito rispondono entro 1 giorno
-
antlers
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
antlers modifiers
Difficoltà 2/5 1-3 ore Idoneità per principianti 57/100
statamic/cms#15832 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Multisite: switching site in the collection listing opens a different entry, not the localizationApertamultisite
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
-
Select field preview disappears after reordering Replicator setsForse già presa @lazerg l’ha presa 4 giorni fa. Apertafieldtypes
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di statamic/cms
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 83/100
nikic/PHP-Parser#1187 ·
-
15.0
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
-
needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
Icinga/icinga-notifications-web#645 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
OpenMage/magento-lts#5865 ·
I maintainer di solito rispondono entro 3 giorni