Skip to main content

Using Variables in KurocoEdge – Static Variables

Overview

KurocoEdge allows you to define static variables within a Rule's Action. These static variables can be reused within the Action's 'Execution' section, with the {$variable} syntax.

What You Will Learn

Where to Define a Static Variable

To begin, first click on the Deploy version in the Draft state that is being edited for this configuration:

Image from Gyazo

Within this version, click the [Add] button (or, if you have an existing 'Rule ID' for which you want to define a static variable, click on that one):

Image from Gyazo

For the purposes of this tutorial, we are going to create a Static Variable within the Response section, in order to use it within a dummy header (which we will afterwards use to test that the variable is being passed on properly).

Next, click on [Add Action] in the Response tab: Image from Gyazo

Within the action, click on 'Condition / Dataset' to expand this section. This is the section where we create Static Variables. Click 'Add Item' to start.

You will be shown a list of conditions in a dropdown – select the 'Static Variable' option:

Image from Gyazo

This will display the 'Name' and 'Value' fields for the Static Variable:

Image from Gyazo

Next, you must choose a name (string) and value (string), and enter them into their respective fields. You can use lowercase, camelCase, kebab-case – or whichever other string format works best for your needs.

Field(s)Input
Namemy_static_variable
Valuetest_value

For demonstration purposes, we will create a dummy variable with the name of my_static_variable and a value of test_value.

Image from Gyazo

Click the [Update] button at the bottom of the screen to save your static variable.

Configure an Action's 'Execution' Settings

Now that we have defined our dummy Static Variable (my_static_variable with a value of test_value), we can use it in our Action's 'Execution' section. The 'Execution' section is where variables are currently intended for use within KurocoEdge.

tip

With the exception of the 'Match' option in 'Conditions / Dataset' section of the action, it is not currently possible to use Static Variables as values of other Conditions. Variables should be used in the 'Execution' section of the Action.

For this tutorial, we will test our variable out by passing it in as the value of a new Header that we will create in our Action's 'Execution' section. To do this, first click on the 'Execution' tab to expand it, then click 'Add Item', then select 'Header' from the dropdown's list of options:

Image from Gyazo

Select the 'Set' operation for the new header:

Image from Gyazo

tip

In the 'Name' field you can enter in the name of the new header that you wish to create. If you click on the empty field, a variety of common header types will be auto-generated as suggestions shown in a list. You can optionally select of those, but it is not necessary. For the sake of this tutorial, we will be creating our own custom dummy header called StaticVariableHeader to correspond with the name of the variable we created above.

Next, add your new variable into the 'Value' field using the {$variable} syntax.

For the header's value, if you only add in the name of the variable without using the curly braces and dollar sign syntax, it will not call the variable you previously defined. In the case of our example it is necessary to enter in the variable as {$my_static_variable} into the header's value field.

Image from Gyazo

Click the [Update] button at the bottom of the screen to save the settings.

Test if the Variable is Working

Now that we have created a new a header, we can test to see if the value of the Static Variable we previously created was passed into the header's value.

Opening up your site in development tools, navigating to the 'Network' section, and re-loading your page – you should now see your new header (named staticvariableheader) appear in the Response headers section (with a value of test_value – which is the same value as the Static Variable we created earlier).

Image from Gyazo

If the new header's value matches the Static Variable's value, it means that it was successfully created and its value was passed into the Action's 'Execution' section as intended.


Support

If you have any other questions, please contact us or check out Our Discord Community.