StoreSpan
Blocks

Variables

Leave values in a block open so each injectable can fill them in, choose the right kind for each value, and fix what saving reports.

A variable is a blank that a block leaves open. Each injectable that uses the block fills the blank with its own value.

In the example block, Free Shipping Promise, the order amount is a variable. One banner says "Free shipping over $75". A banner for a sale says "Free shipping over $50". Both use the same block.

Only Custom HTML & CSS and Template blocks can have variables.

Add a variable

  1. Open the block and find the Variables card.
  2. Press + Add variable.
  3. Fill in the fields below.
  4. Put the cursor where the value belongs in the content and press Insert on the variable's row. This writes {{name}} at that place.
  5. Save the block.
FieldWhat to enter
NameThe name used in the content, as {{name}}. Letters, numbers and underscores. It cannot start with a number.
KindWhat sort of value it is. See Kinds of variable.
LabelThe name your team sees when they fill it in. Up to 200 characters.
DefaultThe value used when an injectable does not set its own.
HelpA hint shown next to the field. Up to 500 characters.
RequiredTurn on if every injectable must give a value.

The Variables card of a block with a number variable and a colour variable

A block can have up to 50 variables. Move up and Move down change their order, and Remove deletes one.

Kinds of variable

Each kind of value may be used only where it is safe. The table shows where, with an example for the block's HTML.

KindUse it forWhere it may goExample
TextA few wordsText, or the value of an attribute<strong>{{headline}}</strong>
Long textA sentence or moreText, or the value of an attribute<p>{{message}}</p>
NumberAn amount. Has Least and Most.Text, an attribute, or a -- style valueover ${{minimum}}
ColourA colourA -- style value onlystyle="--accent: {{accent}}"
LinkA web address to openThe href of a link<a href="{{link}}">Shop now</a>
ImageThe address of one pictureThe src of an image<img src="{{picture}}" alt="">
On/offA yes or noText, or the value of an attributedata-compact="{{compact}}"
ChoiceOne of a list. Has Choices (one per line), up to 50.Text, or the value of an attributeclass="notice {{size}}"

A -- style value is a CSS custom property. Your CSS reads it with var(--accent). It is the safe way to pass a colour or a size into a block's CSS.

Where a variable cannot go

StoreSpan refuses to save a block with a variable in one of these places, because a value there could break the page or run code:

  • inside a <script> or <style> element, or on the CSS tab,
  • in an attribute that runs code, such as onclick,
  • directly in a style value, such as style="color: {{accent}}". Use a -- style value instead,
  • inside an HTML comment,
  • in an attribute value without quotes, or in place of an attribute's name,
  • as only part of a web address, such as href="/sale/{{page}}".

Show content only in some cases

Wrap content in a condition to show it only when the condition is met.

{{#if minimum}}
<p>Free shipping over ${{minimum}}</p>
{{else}}
<p>Free shipping on every order</p>
{{/if}}
You writeThe content shows when
{{#if minimum}}minimum has a value
{{#if minimum gt 50}}minimum is greater than 50
{{#if size eq "large"}}size is exactly large

The comparisons are gt (greater than), gte (greater than or equal), lt (less than), lte (less than or equal), eq (equal) and ne (not equal). When a value is missing, a comparison is never met.

{{else}} is optional. Every {{#if}} needs a closing {{/if}}.

A condition around attributes must wrap whole attributes, not part of one.

Calculate a value

You can add, subtract, multiply and divide inside a variable:

<p>Add ${{minimum - cart_total}} more for free shipping</p>

Use the variable on its own too

A variable gets its value only where it stands alone as {{ name }}. If you use a variable only inside a calculation or a condition, StoreSpan warns you when you save. Such a variable shows nothing.

What saving checks

When you save, StoreSpan compares the content with the variables. A finding in red stops the save. A finding in amber is a warning, and the block is saved.

Finding in redWhat to do
The name is not a valid variable nameUse letters, numbers and underscores, and do not start with a number.
Two variables have the same nameRename one.
The content uses a {{name}} that is not a variable or a visitor detailAdd the variable, or correct the spelling in the content.
A default does not suit its kindCorrect it: a number within its limits, a real colour, a valid address, one of the choices.
A Choice variable has no choicesEnter at least one choice.
A required variable has no default, and injectables already use the blockGive it a default, so those injectables keep a value.
A variable, or a visitor detail, is in a place that is not allowedMove it. See Where a variable cannot go.
The content uses three braces, {{{name}}}Use two braces.
A condition is not written correctlyCheck the {{#if}}, and that it has a closing {{/if}}.
Finding in amberWhat it means
A variable is never used in the contentRemove it, or insert it in the content.
A variable has the same name as a visitor detailThe block's value is used, and the visitor detail is hidden. Rename it if you want the visitor detail.
A variable is used only in a calculation or a conditionIts value is not filled in. Use it on its own in the content as well.

Visitor details are the variables StoreSpan fills in about the shopper, such as the country. See Variables you can insert.

Visitor details are filled in only when the injectable reaches the page through the loader or a BigCommerce widget. With Static Page and Server-rendered delivery they are empty. See Delivery.

Rename a variable

Change the Name and save. StoreSpan rewrites {{name}} everywhere in the block's content, and the injectables that use the block keep the values they had set.

Remove a variable or change its kind

When you remove a variable, the injectables that set a value for it lose that value. When you change its kind, a value that no longer suits the kind is lost too, and the injectable uses the block's default.

Blocks made before variables had kinds

A block created before variables had kinds shows its old values as Text variables. You can change their kind.

On this page