Skip to content

MARS Engine - Config & Environment

The MARS Engine environment provides functions to read and write configuration values.
Use config() to read values defined in the config tab, and setConfig() or setEnv() to add new configuration.

Reading Config

If you want to read config values that you previously defined in the Settings -> Software settings tab, the config() function can be used.

To see what value is assigned to the config key 'default page', call config() with the config key as the first argument:

js
var cnf = config('default page', 'Default value');
write('cnf', cnf);

Output:

json
{
  "cnf": "index.html"
}

Default Value

If the config key does not exist, you can define a default value as the second argument:

js
var cnf1 = config('default page', 'Default value 1');
var cnf2 = config('default page 2', 'Default value 2');
write('cnf1', cnf1);
write('cnf2', cnf2);

Output:

json
{
  "cnf1": "index.html",
  "cnf2": "Default value 2"
}

Setting Config

Use setConfig() or setEnv() to add new configuration values.

You can add new config values with the code below:

js
var setCnf1 = setConfig('cnf_1', 'configuration_1');
var setCnf2 = setEnv('cnf_2', 'configuration_2');
write('setCnf1', setCnf1);
write('setCnf2', setCnf2);

Arrays and Objects

If the value is an array or object, it will be converted to a JSON string.

You can pass multiple arguments after the first one; each will be considered as a value and added to an array of values:

js
var setCnf = setEnv('array_of_values', [1, 2, 3], 'testing', 22);

If you retrieve the env variable "array_of_values", it will be converted to an array automatically:

js
var getCnf = env('array_of_values');
write('array_of_values', getCnf);
write('index_1', getCnf[1]);

Output:

json
{
  "array_of_values": [
    [1, 2, 3],
    "testing",
    22
  ],
  "index_1": "testing"
}
  • write() - Output function for API scripts