Variables
Last updated
Last updated
As we know, variables are used to keep a value and are accessible throughout the workflow.
For instance, an extracted text by the Get Text block can be stored inside a variable. Later you can access that variable in another block.
You are free to choose any name for the variable. But for ease of access to the variable inside a mustache tag, do not include space, at (@), and bracket ([]) in the variable name.
We can use variables created in Java Script in other blocks. To do this, create a golessSetVariable
in a Java Script block before that, you can write code that will calculate the values for this variable.
After that you can pass this variable to other blocks that come after your block that creates this variable.
GoLess utilizes symbols or prefixes in the variables' names. Also, it may use commands to demonstrate a specific purpose or functionality. For instance, $$
indicates that the variable is kept on storage (e.g., $$variableName
).
$$
As we said above, the $$
prefix indicates that the variable value is kept in the storage.
See also: Storage
$push:
By using $push:
as a prefix, you tell GoLess to change the type of variable data to an array. If the variable already has a value, the value will change to the first element in the array. If you assign a value to the variable, GoLess will push this value into the variable instead of overwriting the value of the variable.
Suppose you make a loop through the elements and want to get the text of the element by using the Get Text block and setting the text of the element to a variable with $push:
as a prefix $push:texts
. On the first iteration, the value of the texts
variable is ["Text 1"]
, on the second iteration["Text 2"]
, etc.
$date
- get the current date.
$randint
- generating a random integer.
$getLength
- get the length of some data structure (string, list, etc.).
$slice
- extracting a subset or slice from a data structure.
$multiply
- perform multiplication operation.
$increment
- incrementing a value by one.
$divide
- performing a division operation.
$subtract
- performing subtraction operation.
$randData
- generation of random data.
$filter
- filtering data based on certain conditions.
$replace
- replacing a certain value with another one.
$replaceAll
- replacing all occurrences of a certain value with another.
$toLowerCase
- converts all characters in a string to lower case.
$toUpperCase
- converting all characters of a string to upper case.
$modulo
- performs the operation of taking the remainder from division.
$stringify
- converting some value into a string.