Skip to main content

Overview

info

Setting location:

  • Global Settings - Yes
  • Template Settings - Yes
  • Module Settings - No

This page describes what data variables are and how to use them in the builder.

General information

Data variables are providers for dynamic data. Some of them provide static values though. Data variables do not render anything on the page just because they were created.

We can add as many data variables as we need. There is no limitation in their quantity.

Types of data variables

There are many types of data variables, and each of type serves a different purpose.

  1. Query to DB (GraphQL) - to provide data from DB
  2. Static integer value - to provide Int constant
  3. Static float value - to provide Float constant
  4. Static string value - to provide String constant
  5. Static boolean value - to provide Boolean constant
  6. Static JSON value - to provide JSON constant
  7. Expression - to provide modified values of other data variables by writing expressions

Data variables inheritance and flow

Data variables can be created under different settings types. The following example shows creation of datavar in template settings: Creating data variables

Speaking about the inheritance and flow of data variables, there are two main principles:

1) Sort order of data variables matters inside a single data layer. It is possible to use earlier declared variables inside data variables type GraphQL and Expression.

Example: Use data variable in another data variable basePrice datavar is used inside another datavar called priceCalFormula (1) on the screensot marks "copy variable" icon

2) The data variables with the same names override values of each other between the layers.

note

Override logic is done just by "name" of data variables. So we can override variable of any type by creating variable with same name (type can be different) in the layer with the higher priority.

Example: Data variables flow chart basePrice was overwritten later in template settings, so the result of priceFormula variable is equal to '50'

Pro tip

Being aware of data variables inheritance and flow, we can create quite complex data logic. An example: the first variable fetches the data from DB (let's say a custom meta field), then this variable is used in an expression of the second variable to modify its value somehow based on an information from the current template; then the third variable that also fetches some data from DB based on the unique value of the second variable and so on. The possibilities are truly endless! :)

Using data variables

Data variables are getting evaluated to dynamic data, then dynamic data can be used inside the template with the help of dynamic data template tags.