To add or edit variables, click the Variables button from the sidebar:

Variables allow you to reuse common values, adapt to the device’s characteristics (such as size or color scheme), and do things like dynamically hide or how components. All of these scenarios can be achieved using variables in conjunction with our dynamic values editor:

  • Presenting or hiding a bottom sheet of products.
  • Changing the padding of several elements based on the device’s available width.
  • Formatting the price of a product based on different parameters, such as trial availability.

By default, Superwall has three different type of variables for use:

  • Device: Relates to the device, the app’s install date, bundle ID and more.
  • Product: Represents the products added to the paywall, and their properties. In addition, there are variables for the selected product in addition to the primary, secondary or tertiary product.
  • User: User-specific values, such as their alias ID.

While those will allow you to cover several cases, you can also add your own custom variables too.

Variables dealing with any product period, such as someProduct.period, someProduct.periodly, and other similar variables, do not localize automatically. This is because different languages use varying orders and sentence structures for such terms. If you need them localized, add them as you would any other term and enter localized values for each. Learn more about localization here.

Using Variables

You primarily use variables in the component editor and with dynamic values. When using a variable in text, follow the Liquid syntax to reference one: {{ theVariable }}. For example, to reference a variable in some text, you would:

  1. Select the text component.
  2. Under Text -> click ”+ Add Variable”.
  3. Then, drill down or search for the variable or its corresponding property.
  4. Click on it, and it’ll be added to your text and correctly formatted.

To use a variable with a component property, click on the property and choose Dynamic:

The dynamic values editor will appear. Next to then:, choose your variable and click Save:

Above, the “padding” variable was used. You can ignore the if/then rules above if you simply want to apply a variable, but to dynamically enable or disable them — you can set conditions accordingly. Read the docs over dynamic values to learn more.

You can also hover a property and hold down the Option/Alt key to bring up the dynamic values editor.

Clearing variables

To remove a variable that’s in use, click the property or gear icon (which will be purple when a variable is being used) and selected Clear.

Stock variable documentation

Below are all of the stock variables and their types. You don’t have to memorize any of these — when the variable picker shows, each of the correct liquid syntax appears above every variable, and it be will auto-inserted for you when selected.

PropertyTypeExample
App Install DateText2024-04-11 02:40:44.918000
App User IdText$SuperwallAlias:2580915A-8A2A-40B6-A947-2BE75A42461E
App VersionText1.0.2
Bundle IdTextcom.yourOrg.yourApp
Days Since InstallNumber0
Days Since Last Paywall ViewNumber
Device Currency CodeTextAED
Device Currency SymbolTextAED
Device Language CodeTexten
Device LocaleTexten_AE
Device ModelTextiPhone14
Interface StyleTextlight
Interface TypeTextiphone
Is Low Power Mode EnabledNumber0
Is MacNumber0
Local DateText2024-05-02
Local Date TimeText2024-05-02T21:31:52
Local TimeText21:31:52
Minutes Since InstallNumber7
Minutes Since Last Paywall ViewNumber1
OrientationString“landscape” or “portrait”
Os VersionText17.4.1
PlatformTextiOS
Public Api KeyTextpk_ccdfsriotuwiou23435
Radio TypeTextWiFi
Total Paywall ViewsNumber10
Utc DateText2024-05-02
Utc Date TimeText2024-05-02T17:31:52
Utc TimeText17:31:52
Vendor IdTextCC93GCD-ESB6-4DFF-A165-0963D0257221
View Port BreakpointTextX-Small/Small/Medium/Large/Extra Large/ Extra extra large
View Port WidthNumber844
View Port HeightNumber390

Reference any of the variables above by using the device variable. For example, if you were creating a filter or dynamic value based off whether or not the device was a Mac, you’d write {{ device.isMac }}.

Custom Variables

To create your own variable, click + Add Variable in the sidebar under the Variables section:

The variable editor will be presented:

You’ll be presented with four fields to fill out:

  1. Type: The type of variable to create. Choose State if you’d like the variable to be mutated by tap behaviors. Parameter variables are similar, but initial values can be passed in from your app.
  2. Name: How you will reference the variable. Any name will autocorrect to camel case, i.e. “Cool Variable” will be coolVariable.
  3. Value Type: The variable type. Choose from text, number, or boolean.
  4. Initial Value: The initial value of the variable. This only displays once a variable type has been chosen.

Once you have everything entered, click Save. Your variable will show up in a section in the sidebar under Variables called Params:

From there, they are able to be referenced the same way as any other variable:

Liquid syntax formatting

In text, you can use Liquid filters to modify output. To use filters, add a pipe after the variable. Then, add in one or more filters:

// Results in 17, the absolute value of -17
{{ -17 | abs }}

For example, to capitalize a text variable, you would write:

// If the name was "jordan", this results in "JORDAN"
{{ user.name | upcase }}

Custom Liquid filters

To make it easier to express dates & countdowns we’ve added several non-standard filters to our Liquid engine.

date_add_* and date_subtract_*

These filters add or subtract a specified amount of time to/from a date.

FilterDescription
date_add_secondsAdds the specified number of seconds to a date
date_add_minutesAdds the specified number of minutes to a date
date_add_hoursAdds the specified number of hours to a date
date_add_daysAdds the specified number of days to a date
date_add_weeksAdds the specified number of weeks to a date
date_add_monthsAdds the specified number of months to a date
date_add_yearsAdds the specified number of years to a date
date_subtract_secondsSubtracts the specified number of seconds from a date
date_subtract_minutesSubtracts the specified number of minutes from a date
date_subtract_hoursSubtracts the specified number of hours from a date
date_subtract_daysSubtracts the specified number of days from a date
date_subtract_weeksSubtracts the specified number of weeks from a date
date_subtract_monthsSubtracts the specified number of months from a date
date_subtract_yearsSubtracts the specified number of years from a date

Example Usage:

{{ "2024-08-06T07:16:26.802Z" | date_add_minutes: 30 | date: "%s" }}

Output: 1722929186

countdown_*_partial

These filters calculate the partial difference between two dates in various units. This is usefull for formatting a countdown timer by exach segment.

FilterDescription
countdown_minutes_partialReturns the remaining minutes in the current hour
countdown_hours_partialReturns the remaining hours in the current day
countdown_days_partialReturns the remaining days in the current week
countdown_weeks_partialReturns the remaining weeks in the current month (assuming 4 weeks per month)
countdown_months_partialReturns the remaining months in the current year
countdown_yearsReturns the full number of years between the two dates

Example Usage:

{{ "2024-08-06T07:16:26.802Z" | countdown_hours_partial: "2024-08-06T15:30:00.000Z" }}:{{  "2024-08-06T07:16:26.802Z" | countdown_minutes_partial: "2024-08-06T15:30:00.000Z" }}

Output: 8:33

countdown_*_total

These filters calculate the total difference between two dates in various units.

FilterDescription
countdown_minutes_totalReturns the total number of minutes between two dates
countdown_hours_totalReturns the total number of hours between two dates
countdown_days_totalReturns the total number of days between two dates
countdown_weeks_totalReturns the total number of weeks between two dates
countdown_months_totalReturns the total number of months between two dates
countdown_years_totalReturns the total number of years between two dates

Example Usage:

{{ "2024-08-06T07:16:26.802Z" | countdown_days_total: "2024-08-16T07:16:26.802Z" }}

Output: 10

All these filters expect date strings as arguments. Anything that Javascript’s default date utility can parse will work. For countdown filters, the first argument is the starting date, and the second argument (where applicable) is the end date.

The countdown_*_total filters calculate the total difference, while the countdown_*_partial filters calculate the remainder after dividing by the next larger unit (except for years).

For countdown_months_total and countdown_years_total, the calculations account for varying month lengths and leap years.

All countdown filters assume that the end date is later than the start date. If this isn’t always the case in your application, you may need to handle this scenario separately.

Snippets with variables

If you create a group of components built off of variables and conditions, save it as a snippet to reuse. There are several stock snippets built this way. For example the Product Selector snippet:

Adding this snippet shows your products in a vertical stack:

When one is selected, the checkmark next to it is filled in. This is achieved with stock variables (i.e. the selected product) and then changing layer opacity based on if the checkmark’s corresponding product is selected or not: