Skip to main content

Variables

Nudge provides a powerful templating system to personalise UI elements such as profile picture URLs, text, and other dynamic content. This guide explains how to use Nudge's templating syntax to create personalised experiences.

Templating Syntax

The templating system uses the following regex to identify placeholders in strings:

\{\{(.*?)\}\}

A string can contain substrings matching this regex. For example:
"Hey {{U.name}}, Your age is {{U.age}}"

Templating Parts and Uses

Template SyntaxPartsUse Case
{{U.variable_name}}2 (U, variable_name)User Templating
{{D.l.variable_name}}3 (Data Source, list, variable_name)Task Templating in a list
{{D.1.variable_name}}3 (Data Source, Index, variable_name)Task Templating for a specific index
{{D.variable_name}}2 (Data Source, Variable Name)Task Templating while using in list view or step view
{{R.variable_name}}2 (R, variable_name)Reward Templating
{{A.id.variable_name}}3 (A, api id, variable_name)API Templating
{{S.variable_name}}2 (S, variable_name)Referral Templating
{{L.l.variable_name}}3 (Leaderboard, list, variable_name)Leaderboard Users
{{C.variable_name}}2 (Leaderboard Current User, variable_name)Leaderboard Current User
{{W.variable_name}}2 (W, variable_name)Wallet Templating
{{G.variable_name}}2 (G, variable_name)Global Variables
{{X.variable_name}}2 (X, variable_name)Root Variables

Advanced API Templating

For API templating, variables can include | to represent a nested structure in a JSON response or *i to represent a specific index in an array.

Examples:

  • {{A.id.users|name}} retrieves the name field from the users array.
  • {{A.id.users*1|name}} retrieves the name field from the users array at index 1.

Fallback Values

You can specify fallback values using =.
For example:
{{U.name=SampleUser}} will display "SampleUser" if U.name is not available.

API Parameter Override

You can override API parameters by specifying them in the root key.
Example:
api = ["api_id?key1=value1&key2=value2"]

At a Glance: Templating Prefixes

PrefixDescription
DTask
TTask Property
EEvent Property
RRewards
UUser
AAPI
SReferral
WWallet
GGlobal Variables
XWidget Variables

By leveraging these templating options, you can dynamically personalise your UI to create engaging and user-specific experiences.