GuidesAPI ReferenceChangelogDiscussions
Log In

Variables

Built-in inputs for getting context on the user

Introduction

Variables serve as the contextual backbone of your experiences. They provide your with the situational awareness to know who the user is, or what page they are on. Use them to introduce personalization, product promotion, or as the gatekeeper to a custom experience.

Using a Variable

πŸ“˜

Syntax Cheat Sheet

Retrieving a variable in HTML:{{object.property}}

Retrieving a variable in Javascript: Tapcart.variables.object.property

In the Tapcart Text Editor

Variables work out of the box as long as you are building inside of the Tapcart Custom Blocks editor (In the HTML or Javascript tabs). No further setup is required beyond using the proper syntax. Variables can be retrieved by identifying the relevant object, and the specific property you want to access.

In a Custom Hosted Solution

Make sure you've already installed the relevant SDK. The method for fetching a Variable in HTML will not work in your own hosted solution unless you've manually implemented Handlebars.js or another templating language. The method for retrieving in Javascript will work as is as long as you setup the SDK.

Null Values

If there's not have enough context to retrieve a variable, it will return a null value instead. This could occur if using {{customer}} and the user isn't signed in, or if using{{product}} but the user is not on a product page.

Variable Preview Values

To test variables (without hardcoding their values) in the Tapcart Text Editor, you can apply a Variable Preview Value . To do this, enter the editor, select the 'Settings' tab, and use the text box to assign preview values. If a variable receives a value in this text box, the editor will automatically assign this value to the occurrence of the variable in the block preview.

If seeking to test Variables outside of the Text Editor, you'll need to mock values to the Variables used in your Javascript.