1. Concepts
  2. Variable Substitution

Concepts

Variable Substitution

Variable substitution is the process whereby expressions in an action definition are substituted for the data in the action context they refer to.
overview

Action Context

When an action on a stub is opened or run, the action context is created from multiple related components.

Example action context:

loading...

Substitution types

Substitution happens in one of two ways: inline text substitution and value replacement substitution.

TIP

When editing a field or a json string, you can use the Ctrl + Space keyboard shortcut to see the available context variables.

Inline text substitution

Inline text substitution is used for when you want to use something from the action context as part of text.
Example definition:

loading...

Substituted definition

loading...

This form of substitution is powered by handlebars.

Value replacement substitution

Value replacement substitution is used when you want to use something from the action context as the entire substituted value. This is useful for referring to parts of the action context that are not numbers or text.
Example definition:

loading...

Substituted definition

loading...

Note: This form of substitution cannot be used inline (part of text)

Nested Value replacement substitution

TIP

If you want to use inline substitution, you could maybe try the Handlebars dynamic lookup helper which allows you to dynamically select a value from a data structure by specifying one or many keys.

This type of value replacement substitution enables you to retrieve a value from a dynamic data path, substituting a part of the path with a value from a different data path.

eg. ~~stub.data.actors[~~stub.data.actor_name].awards

In the example, the data path is stub.data.actors.actor_name.awards. The actor name could be anything the user selects resulting in the awards for the selected actor. This is done by substituting the actor_name key name in the data path with the value at data path stub.data.actor_name. Encapsulate this Value Substitution in square brackets, [].

To substitute the entire actor object, use ~~stub.data.actors[~~stub.data.actor_name]

Example template and stub data structure:

loading...

Example definition:

loading...

Substituted definition

loading...