You can use expressions to sophisticate the customization of your templates.
Expressions must be surrounded by double curly braces {{
and }}
.
For example, you can use expressions to adjust the duration of an element based on the value of a variable plus a number of seconds.
{
"comment": "Expressions example",
"resolution": "full-hd",
"variables": {
"text_element_duration": 10
},
"scenes": [
{
"background-color": "{{bgColor}}",
"elements": [
{
"type": "text",
"style": "005",
"text": "{{message1}}",
"duration": "{{text_element_duration}}"
},
{
"type": "audio",
"src": "https://www.json2video.com/audio/example.mp3",
"duration": "{{text_element_duration + 5}}"
}
]
}
]
}
In this example, the text element will be displayed for 10 seconds and the audio element will play for 15 seconds.
Examples of expressions
Here are some examples of expressions that you can use in your templates:
-
{{var1 + var2 - 5}}
returns the sum of the values ofvar1
andvar2
minus 5. -
{{var1 * var2}}
returns the product of the values ofvar1
andvar2
. -
{{var1 / var2}}
returns the quotient of the values ofvar1
andvar2
. -
{{min(var1, var2)}}
returns the minimum value betweenvar1
andvar2
. -
{{max(var1, var2)}}
returns the maximum value betweenvar1
andvar2
. -
{{var1}}
returns the value ofvar1
. -
{{var1==2 ? "two" : "not two"}}
returns "two" if the value ofvar1
is 2, and "not two" if it is not 2.