Altoura Training
Copy link
Creator

Variable Interpolation

**Variable interpolation** is a way to embed variable values directly into text strings. Instead of showing fixed text, you can make text dynamic by inserting variable values.

The syntax is simple: wrap the variable name in double curly braces: {{variableName}}

Before using the examples, create the referenced variables in the Variables pane. Use Set Variable actions to assign their values before the display action: choose Set Value for a literal value or Set Expression for a calculation. Enter Set Expression formulas without {{ }}.

In the examples, Variable: score = 95 describes the value to assign. Select score in Set Variable and enter 95 as its value; do not enter the entire assignment as an expression. Display text examples use the Body field unless Title is specified.

Basic Syntax

"Hello {{userName}}, you scored {{score}} points."

When this text is displayed:

  • {{userName}} is replaced with the value of the userName variable
  • {{score}} is replaced with the value of the score variable

Example:

  • If userName = "John" and score = 95
  • The text becomes: "Hello John, you scored 95 points."

Common Uses

Interpolation is supported in the Title and Body fields of Show Text and Show Panel. Verify other fields in the target client before relying on it there. Here are the most common uses:

Show Text Action

Variable: userName = "Sarah"
Variable: completionTime = 120

Action: Show Text
Title: "Training result for {{userName}}"
Body: "Great job, {{userName}}! You completed the training in {{completionTime}} seconds."

Displays:
Title: "Training result for Sarah"
Body: "Great job, Sarah! You completed the training in 120 seconds."

Show Panel Title and Body

Variable: questionNumber = 3
Variable: totalQuestions = 10
Variable: attemptsRemaining = 2

Action: Show Panel
Title: "Question {{questionNumber}} of {{totalQuestions}}"
Body: "You have {{attemptsRemaining}} attempts remaining. Choose wisely."

Displays:
Title: "Question 3 of 10"
Body: "You have 2 attempts remaining. Choose wisely."

Feedback Messages

Variable: score = 87
Variable: passingScore = 70

Body: "Score: {{score}}. Passing score: {{passingScore}}. Result: {{score >= passingScore ? 'Passing' : 'Failing'}}."

Displays: "Score: 87. Passing score: 70. Result: Passing."

All Variable Types

Interpolation works with all variable types:

String Variables

Variable: selectedAnswer = "Option A"
Body: "You selected: {{selectedAnswer}}"
Displays: "You selected: Option A"

Number Variables

Variable: score = 92
Variable: attempts = 3
Body: "Score: {{score}}, Attempts: {{attempts}}"
Displays: "Score: 92, Attempts: 3"

Boolean Variables

Variable: isComplete = true
Body: "Complete: {{isComplete}}"
Displays: "Complete: true"

Note: Booleans display as "true" or "false". For user-friendly text, use a ternary expression (see below).

Array Variables

Variable: completedSteps = ["Read Instructions", "Identify Valve", "Turn Valve"]
Body: "You've completed {{len(completedSteps)}} steps."
Displays: "You've completed 3 steps."

Arrays can interpolate directly as comma-separated text. For example, {{completedSteps}} displays Read Instructions,Identify Valve,Turn Valve. Use len() when you need the item count.

To display one item, use its index in square brackets. Indexing starts at 0, so scores[0] is the first item and scores[1] is the second:

Variable: scores = [85, 92, 78]
Body: "First attempt: {{scores[0]}}. Second attempt: {{scores[1]}}."
Displays: "First attempt: 85. Second attempt: 92."

Advanced: Using Expressions in Interpolation

In addition to simple variable names, you can use Altoura Expression Language (AXL) expressions inside {{ }}. Interpolation reads values and computes display text without changing stored variables. Use Set Variable to save a calculated result.

Ternary Expressions (If-Then-Else)

Variable: score = 85
Variable: passingScore = 80

Body: "You {{score >= passingScore ? 'passed' : 'failed'}} the quiz!"
Displays: "You passed the quiz!"

Formula: condition ? valueIfTrue : valueIfFalse

Another example:

Variable: attempts = 2
Body: "{{attempts == 1 ? 'This is your first attempt.' : 'You have attempted ' + attempts + ' times.'}}"
// If attempts = 2, displays: "You have attempted 2 times."

Arithmetic

Variable: score = 92
Variable: maxScore = 100

Body: "You scored {{(score / maxScore) * 100}} percent."
Displays: "You scored 92 percent."

Function Calls

Variable: completedSteps = ["step1", "step2", "step3"]
Body: "Completed {{len(completedSteps)}} of 5 steps."
Displays: "Completed 3 of 5 steps."

Available functions:

FunctionPurpose
len(value)Return the length of a string or array.
clamp(value, min, max)Constrain a number to the specified range. All arguments must be finite numbers, with min <= max.
now()Return the current Unix timestamp in milliseconds.
random()Return a random number greater than or equal to 0 and less than 1.
concat(value, ...items)Return a new array or string by joining values. Method form, such as completedSteps.concat(['step3']), is also supported.
contains(value, item)Check whether an array contains an item or a string contains a substring. includes(value, item) is an alias; method forms such as completedSteps.includes('step3') are also supported.
filter(array, predicate)Return a new array containing items that match a quoted AXL expression. Method form array.filter(predicate) is also supported.

For example, check whether a step is in a list:

Variable: completedSteps = ["step1", "step2"]
Body: "Step 2: {{(contains(completedSteps, 'step2')) ? 'Complete' : 'Pending'}}."
Displays: "Step 2: Complete."

For filter, put the predicate in quotes. Within it, item is the current element and index is its position, starting at 0. The predicate can reference other variables and must return true or false. JavaScript arrow functions are not supported.

Variable: scores = [85, 62, 91]
Variable: passingScore = 80
Body: "Passing attempts: {{len(filter(scores, 'item >= passingScore'))}}."
Displays: "Passing attempts: 2."

Using concat or filter in display text leaves the original array unchanged. To update a list, select the array in Set Variable and use Set Expression, such as concat(completedSteps, ['step3']).

String Concatenation

Variable: firstName = "John"
Variable: lastName = "Smith"

Body: "Welcome {{firstName + ' ' + lastName}}"
Displays: "Welcome John Smith"

Undefined Variables: Default Behavior

What happens if you try to interpolate a variable that doesn't exist or is uninitialized?

// userName has not been created
Body: "Hello {{userName}}, welcome!"
Displays: "Hello --, welcome!"

An undefined value displays as --. An existing empty String displays as empty text. An expression evaluation failure displays [Error].

To avoid this:

  • Create variables before referencing them and use Set Variable for the values the text needs.
  • For an existing String variable, use a ternary expression to provide fallback text when its value is empty:
Variable: userName = ""
Body: "Hello {{userName === '' ? 'Guest' : userName}}, welcome!"
Displays: "Hello Guest, welcome!"

This fallback handles an empty String; create userName before using it.

Real-World Examples

Quiz Feedback

Variable: score = 87
Variable: maxScore = 100
Variable: userName = "Sarah"
Variable: feedbackLevel = score >= 80 ? "great" : "okay"

Body: "{{userName}}, you did {{feedbackLevel}}! You scored {{score}} out of {{maxScore}} ({{(score / maxScore) * 100}} percent)."

Displays: "Sarah, you did great! You scored 87 out of 100 (87 percent)."

Set score, maxScore, and userName first. Then select the String variable feedbackLevel in Set Variable and use Set Expression with score >= 80 ? 'great' : 'okay' before the display action.

Personalized Status Message

Variable: currentStep = 3
Variable: totalSteps = 5
Variable: userName = "John"

Body: "{{userName}}, you're on step {{currentStep}} of {{totalSteps}}. {{totalSteps - currentStep}} steps remain."

Displays: "John, you're on step 3 of 5. 2 steps remain."

Time-Based Messaging

Variable: elapsedSeconds = 125

Body: "You've spent {{elapsedSeconds >= 60 ? 'at least a minute' : 'under a minute'}}."

Displays: "You've spent at least a minute."

Conditional Content

Variable: passScore = 80
Variable: actualScore = 92
Variable: feedbackURL = actualScore >= passScore ? "https://advanced.example.com" : "https://basic.example.com"

Body: "{{actualScore >= passScore ? 'Advanced' : 'Basic'}} content: {{feedbackURL}}"

Displays: "Advanced content: https://advanced.example.com"

Set passScore and actualScore first, then calculate the String variable feedbackURL with Set Expression before displaying it.

Where Interpolation Works

Interpolation is available in:

LocationExample
Show Text — Title and Body"You scored {{score}}."
Show Panel — Title and Body"Question {{currentQuestion}} of {{total}}"
Other action fieldsCheck support in the target client; a text input alone does not guarantee interpolation.

Where it doesn't work:

  • Variable names and fields in the Variables pane
  • Condition expressions and Set Expression formulas (use variables directly, without {{ }})

Testing Interpolation

Use Set Variable actions before the display action, then save and start Preview to check the resulting text.

  1. Create a String variable named userName.
  2. Add Set Variable before Show Text. Select userName and use Set Value to enter Alice.
  3. Set Show Text's Body to Hello {{userName}}, welcome!.
  4. Save and start Preview. Confirm that the text reads Hello Alice, welcome!.
  5. Exit Preview, change the Set Variable value to Bob, and save.
  6. Start Preview again and confirm that the text reads Hello Bob, welcome!.

Best Practices

Keep interpolation readable

Avoid overly complex expressions in {{ }}. If it's hard to read, it's hard to maintain. Consider breaking complex logic into separate variables.

Always initialize variables

Create each variable and use Set Variable to assign the value your text needs before displaying it. A new String starts empty; use a ternary expression when empty text needs a friendly fallback.

Use ternary for conditional text

Use a ternary expression such as {{score >= 80 ? 'Passed' : 'Try again'}} to choose the text displayed by one action.

Be consistent with variable names

If you use userName in some places and learnerName elsewhere, you'll confuse yourself. Pick a naming convention and stick with it.

Test with real data

Preview your training with actual variable values to make sure the interpolated text looks good and reads naturally.

Use friendly text

Even if score = 92, consider displaying "Great job!" instead of just the number. Use ternary expressions to show friendly feedback.

Common Mistakes

Next Steps

Learn more about:

Was this page helpful?
© 2026 Altoura
Enter a page title, topic, or keyword.