GuidesAPI ReferenceChangelogDiscussions
Log In

Variables

Built-in inputs for getting context on the user

Introduction

Variables serve as the contextual backbone of your block. They provide your block 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

Block 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.

πŸ“˜

Syntax

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

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

Null Values

If the Custom Block does 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), you can apply a Variable Preview Value in the Custom Blocks text editor. 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.