Sometimes you want to create a variable number of scenes, for example if you want to create a slideshow with a variable number of images.
You can do this by using an array of objects as the value of a variable and the iterate
property to iterate over the array.
This is an example of a template that creates a slideshow with a variable number of images:
{
"comment": "Variable number of scenes example",
"resolution": "full-hd",
"variables": {
"my_images": [
{
"title": "Houses of Parliament",
"image_url": "https://cdn.json2video.com/assets/images/london-01.jpg",
"duration": 5
},
{
"title": "St. Paul's Cathedral",
"image_url": "https://cdn.json2video.com/assets/images/london-02.jpg",
"duration": 8
}
]
},
"scenes": [
{
"iterate": "my_images",
"duration": "{{duration}}",
"elements": [
{
"type": "image",
"src": "{{image_url}}"
},
{
"type": "text",
"text": "{{title}}",
"style": "005"
}
]
}
]
}
The iterate
property in the scene object is used to iterate over the my_images
array,
creating a scene for each element in the array.
The properties of the current item in the array are available as variables in the scene
(e.g. {{title}}
, {{image_url}}
, {{duration}}
),
and can be used in the same way as static values or other variables.