Looping %choice% bug when changing number of choices!
Hey all, I’ve found a bug in one of my templates (based on excellent work by @Andrew_Nimbler )
The template (see below) allows the user to choose a number of modules to display, then choose the modules from the corresponding choice fields, and finally outputs those choices on screen in the order you choose them.
The issue is that if I choose say 5 modules, populate them, then decide I want 7 modules, it somehow skips a few numbers in theloop.indexso instead of outputting 1, 2, 3, 4, 5 (I haven’t chosen 6 or 7 yet) - it instead outputs 1,4,5,6,7 (see the 'Banner ' ~ loop.index0variable - which means the 6th and 7th choice modules will populate the now vacant 2nd and 3rd place!
This isn’t good as it means the modules no longer correspond with my choice order - which means broken emails!Here is my code - can you figure out where I’m going wrong and how I could improve on this? -
Looping %choice% bug when changing number of choices!
Its hard to debug when we can't see the template. What does widget_data|pprint yield?
Is there a feature missing in the email drag and drop editor that you're trying to compensate for with this email template? You might can make a custom email module that will work in the drag and drop editor for each missing feature, then leverage the DnD editor for things like "full width" and "two column" options.
If the above is not an option, I'd honestly put it all in one module and skip the multi-module/separate choice field route – but I say that not knowing how many fields each module has and how complicated each module is in your original template.
I like kudos almost as much as cake – a close second.
Looping %choice% bug when changing number of choices!
haha you're exactly right. The way the code was indented I just skipped over it. Sorry You should pretty print widget_data. I have a feeling there are some extra modules in there that are getting skipped over. Looking at that data might give you some answers
{{ widget_data|pprint }}
I like kudos almost as much as cake – a close second.
Looping %choice% bug when changing number of choices!
It looks like the issue occurs as soon as I choose to have more sections in sections_field (6 or above) than I have options in the layout variable (five choices).