0
votes

I merged values of two arrays in a new array.

But I would like to take random values from this array and put them in a loop. That those values iterate in this loop.

{% set myArray = [] %}
{% set list1 = options.transitions_repeater %}
{% set list2 = options.transitions_wahou_repeater %}

{% set myArray = list1|merge(list2) %}

{% for key, val in myArray %}
    {{ val|join(', ') }}
{% endfor %}

{% for item in options.projets %}
<li data-transisition="{{ myArray }}"></li>
{% endfor %}

I got the message : Array to string conversion in XX on line XX

Array

Output :
animBottom
animTop
animLeft
directionRight
circles
cube

1

1 Answers

0
votes

Your merged list is still a multidimensional array.You could solve your issue with the following code, however it's preferable to move the logic of creating the (single dimensional) array to your controller (then you could remove the filter first in the snippet)

{% for item in options.projets %}
<li data-transisition="{{ myArray[random(myArray| keys)] | first }}"></li>
{% endfor %}

demo