Not certain exactly what you're trying to do, but seems like you could just use a dict. then you can set the keys to whatever string you want. Essentially mimicking the functionality you're wanting, in a safer way.
I'm not sure I understand your usecase as described but have you looked into "Variable Within loops"? Your description sounds like this could be used to add key value pairs to an object rather than declaring new valiables for each loop.
However if you repeat the content element multiple times (I probably didn't make this point clear before)
it will always use the value of the last one for all
using your example:
If the first layout uses option 1, the second 2 and the third 3
width_one would be 100px for all of them.
That's why I needed unique variable names.
However I think I will simply limit the number you can repeat that element to 3
and add the complete layout (with the particular width) in each iteration of the loop... not a very elegant solution but it will work for now and probably most of our emails.
(of course I could do 3 separate elements without repeating one but I think that would be even worse)
I just don't understand why I can't simply do something like
Not certain exactly what you're trying to do, but seems like you could just use a dict. then you can set the keys to whatever string you want. Essentially mimicking the functionality you're wanting, in a safer way.
thanks for the links. I thought I had already checked out the dict option but I have overlooked the New List Operations. I solved it by using dict_var.update
{% if item.col_layout == 3 %}
{% set test = dict_var.update({'img_width_var': '300'}) %}
{% set test = dict_var.update({'txt_width_var': '300'}) %}
{% endif %}
{% if item.col_layout == 2 %}
{% set test = dict_var.update({'img_width_var': '200'}) %}
{% set test = dict_var.update({'txt_width_var': '400'}) %}
{% endif %}
{% if item.col_layout == 1 %}
{% set test = dict_var.update({'img_width_var': '100'}) %}
{% set test = dict_var.update({'txt_width_var': '500'}) %}
{% endif %}
Also I posted a screenshot of the module. I hope that explains what I was trying to do 🙂
Because the 3 rows are all inside one group I was afraid it would override the width variables of the first and second row with the values of the last element again but it in this case it didn't. It works!