Skip to contentSkip to navigationSkip to topbar
Rate this page:
On this page

Set Variables Widget

Studio uses Widgets to represent various parts of Twilio that can then be stitched together in your Studio Flow to build out robust applications that require no coding on your part.



New to Twilio Studio? Check out our Getting Started guide!

The Set Variables Widget allows you to save key/value pairs as variables that are available to the global context of your Studio Flow throughout its execution, meaning that they can be used across multiple Widgets within a given Flow.

A simple Studio Set Variables widget, where the key is bar and value is foo.

Variables you set through this Widget will be accessible throughout your Flow via other Widgets under the key {{flow.variables.<key>}}. This allows you to dynamically update your variables throughout the Flow's execution. For instance, you can use variables to increment counters or change appointment times.

Required Configuration for Set Variables

required-configuration-for-set-variables page anchor

The Set Variables Widget must have at least one key and one value to function properly. Variables can have static values like a single number or a string, or dynamic values set via the Liquid templating language.

KeyThe name of this variablefavorite_colorN/A
ValueThe value tied to the variable's keygreenN/A

Once set, your variable will be accessible in Liquid via {{flow.variables.<key>}}. A few notes on variables:

  • Variable names are case sensitive. Foo is a different variable than foo .
  • The same key may be set in different Widgets. This allows you to update a value.
  • The key itself cannot be a Liquid variable, but the value can be a Liquid variable
  • You can define multiple key/value pairs within one Set Variables Widget

For more in-depth information on working with variables in your Studio Flow, please see this user guide.

Set Variables Transitions

set-variables-transitions page anchor

These events trigger transitions from this Widget to another Widget in your Flow. For more information on working with Studio transitions, see this guide.

NextContinues the execution of your Flow once the specified variables are set.

Example: a Flow with a variable counter

example-a-flow-with-a-variable-counter page anchor

The following Flow uses the Set Variables Widget to set up a counter. An incoming call triggers the Flow. When the Flow first starts, the variable num is created and its initial value is 0. The Flow loops until the num variable is equal to 3 and then exits.

The Flow also uses the Say/Play Widget to speak the value of the num variable to the caller, and the Split Based On... Widget to evaluate whether the Flow should continue looping or exit, based on whether or not the counter is greater than 2.

Set Variable Studio Flow.

Below is the configration for the Set Variables Widget:

Configuration for set variable counter.

The key is num and the value is a Liquid Templating Language expression:

{% if flow.variables.num %}
{{flow.variables.num | plus: 1}}
{% else %}
{% endif %}

The expression checks to see whether the num variable has already been created. If it has, it then increments the value by one. If it hasn't been created yet, it sets the initial value to 0.

Now that you know the basics of the Set Variables Widget, you may want to dig into the Liquid Templating Language:

We also have step-by-step tutorials that will show you how to to use and evaluate variables in Studio:

We can't wait to see what you build!

Rate this page: