- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page
creating array from dynamically generated widgets
Feb 7, 2017 3:44 PM
I am using a Choice and Loop to allow the person editing to page to choose the number of background images they would like to make available to the page.
{% set bg_num = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] %} {% choice "bg_num_choice" label="Number of Background Images", value="3", choices="{{ bg_num }}", export_to_template_context=True %} {% for options in bg_num %} {% if loop.index <= widget_data.bg_num_choice.value %} {% image_src "bg_img" label="Background Image", unique_in_loop=True, export_to_template_context=True %} {% endif %} {% endfor %}
As you can see, based on the number chosen this will enable that many Image src modules on the page.
The issue that I am having is that I now need to choose one of these at random (each time the page loads) and assign it to the div:
<div class="home_body_wrapper" style="background: url({{ Assign Here }});"> </div>
To do this I know that I need to collect the src values of the modules that are created into an array, then use the random filter to print the value where I need it.
The problem is that I have to create the array dynamically. I cannot set the array values static because I would either have empty values or have to change the array based on how many images are used.
How can I dynamically add these modules' values to an array?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content