Cache variables
"Cache variables" are named values you can use anywhere - in an element's text or inside an automation - written as {{name}}. They're created in the "Cache variables" window in the editor (the button in the builder's top bar).
A cache variable is saved on the visitor's own device (localStorage) - not shared between different visitors. A returning visitor keeps their value. If you need data shared by everyone (inventory, comments, a contact form, etc.) - you need a server-side data table (sdb.*, see the "Data tables" chapter), not a cache variable.
How to create a variable
- Variable name: must start with a letter or underscore, and contain only letters, digits and underscores (e.g. score, user_name - not 1score or user-name).
- A duplicate name is rejected - every variable needs a unique name.
- You can set a default value, loaded only on the first visit; on a returning visit, the saved value takes over.
- There's no "type" setting - every variable is really text, and numeric/boolean comparisons (in conditions, for example) happen automatically based on the content.
For convenient use inside any text field (in the builder or the automation editor) - there's a "+ variable" button next to most text fields that opens a list of the defined variables and inserts {{name}} at the cursor position with one click.
An automation can also "listen" for a change in a specific variable's value - the "Variable changed" event fires every time that variable's value actually changes (not on every write - only when the new value differs from the previous one). Detail on this event type is in the "Events" chapter.