String Substitution

Many text fields and rules in GMetri support substitution out of the box.

What is String substitution?

Let's say you have Text element, and you want to show the user his/her score, or a value that you captured earlier. How can you do that?

By adding the following in the text element:

Hi {{firstname_var}}!

Your current score is {{score}}

and the values in the text element will get replace with the corresponding variables.

To prevent escaping of special characters, you can use triple curly brackets {{{variable_name}}} (Case Sensitive)

What are the values that I can substitute?

Apart from Custom Variables, Global Variables and Autogenerated Variables, there are a few additional things available to you that you can substitute. These are:

  • viewer_token: The token used to authenticate the viewer

  • session_uuid: The unique identifier for this session. Unique for every page load.

  • organization_slug: The identifier for the current workspace

  • deployment_slug: The identifier for the current deployment

  • scene_id: Contains the current scene id

  • deployment_url: The URL that the viewer uses to access this experience

Example

You can use variables in text elements through substitution

Let's say you have a Number variable with the name count. To view the value of count in a text element, you can add the text Count: {{count}} in the text element. You will then see something similar to what you see in the experience below.

To show the value of a variable in a Text element, add the name of the variable you want in double curly brackets like {{variable_name}}

Last updated