Custom slots (targets)
How it works
Your customers see slot content as part of SparkLayer's interfaces, in a fixed place such as the top of My Account. Behind the scenes, each slot has an ID, such as spark-slot-my-account.
You turn on the slots you want, at Storefront,Options (opens in your SparkLayer Dashboard in a new tab) or in your Core Script. Your developer then adds a <template> element with the same ID anywhere in your theme. SparkLayer takes the content of the template and shows it in that slot's place in the interface.
Turn the slot on
Your theme
SparkLayer interface
You can use slots for things like:
| Use | Example |
|---|---|
| Promotional content | A message in the My Account that customers see as soon as they sign in, such as announcing a new product line. |
| Adding links | Links in the My Cart, such as downloadable CSV templates. |
| Order complete content | Offers or promotions when a customer completes an order, such as asking for a rating. |
With some extra code in your theme, the content can also change for each customer or order:
| Use | Example |
|---|---|
| Customer-specific | Show different content depending on who the customer is and which customer group they're in, such as a promotion for the VIP group. |
| Order-specific | Show a message based on the order contents or total, such as encouraging customers to add more products when the order is under $100. |
| Market-specific | Show different content for each country or market you sell to, such as delivery terms for customers in the EU. |
Slot locations
Each slot appears in one place in the interfaces:
| Slot | Where it appears | ID |
|---|---|---|
| My Account | At the top of the My Account, above Recent Activity. | spark-slot-my-account |
| My Order | At the top of the My Cart, below the search box and above the products. | spark-slot-my-cart |
| Order Complete | On the order complete screen, below the Thank you for your order! message. | spark-slot-order-complete |
| Cart Shipping Step | On the Shipping step of the checkout. | spark-slot-cart-shipping-step |
| Cart Payment Step | On the payment (Review & Pay) step of the checkout. | spark-slot-cart-payment-step |
| Purchase Summary Header | Above the purchase summary when a customer views a purchase. | spark-slot-purchase-summary-header |
| Purchase Summary Footer | Below the purchase summary when a customer views a purchase. | spark-slot-purchase-summary-footer |
| Cart Line Item | Below each product line in My Cart. | spark-slot-my-cart-line-item |
In the My Account interface, you can also choose where the My Account slot sits among the other sections. See Reorder or hide sections.
You can't add a slot anywhere else, or move one. For what else you can change in the widgets, and what needs a developer, see What you can and can't change.
Before you start
- Edit access to your theme code (or a developer who has it), to add the slot templates.
- An up-to-date Core Script, so every slot on this page is available. Check it at Storefront,Widgets,SparkLayer version (opens in your SparkLayer Dashboard in a new tab).
- A signed-in B2B customer account to check how your content looks, as slot content isn't shown to anyone else.
Turn on the slots
Turn on each slot you want to use. You don't need code:
- Go to Storefront,Options (opens in your SparkLayer Dashboard in a new tab) and open Custom slots.
- Click Add slot and choose the slot you want to use. Repeat for each slot.
- Click Save & publish. See Storefront options.
Turn on the slots in the Core Script (for developers)
Instead of Storefront options, add showSlots to the display section of your Core Script, listing the IDs of the slots you want to use. This example turns on all 8:
display: {
showSlots: [
'spark-slot-my-account',
'spark-slot-my-cart',
'spark-slot-order-complete',
'spark-slot-cart-shipping-step',
'spark-slot-cart-payment-step',
'spark-slot-purchase-summary-header',
'spark-slot-purchase-summary-footer',
'spark-slot-my-cart-line-item',
],
},<!-- SparkLayer Core Script: in your theme, just before </head>.
Already have window.sparkOptions? Add just the setting to it. -->
<script>
window.sparkOptions = {
display: {
showSlots: [
'spark-slot-my-account',
'spark-slot-my-cart',
'spark-slot-order-complete',
'spark-slot-cart-shipping-step',
'spark-slot-cart-payment-step',
'spark-slot-purchase-summary-header',
'spark-slot-purchase-summary-footer',
'spark-slot-my-cart-line-item',
],
},
};
</script>Add content to a slot
This step is for your developer, or whoever edits your theme's code. For each slot you've turned on, add a <template> element to your theme with the slot's ID as its id, and put your content inside it. For a ready-made styled message, see Examples you can use.
Example templates for each slot
<!-- Example code for the My Account slot -->
<template id="spark-slot-my-account">
<div class="my-content">
Content here will show in the My Account section.
</div>
</template>
<!-- Example code for the My Cart slot -->
<template id="spark-slot-my-cart">
<div class="my-content">
Content here will show in the My Order section.
</div>
</template>
<!-- Example code for the My Order slot -->
<template id="spark-slot-order-complete">
<div class="my-content">
Content here will show in the Order Complete section.
</div>
</template>
<!-- Example code for the Cart Shipping Step slot -->
<template id="spark-slot-cart-shipping-step">
<div class="my-content">
Content here will show in the Cart Shipping Step section.
</div>
</template>
<!-- Example code for the Cart Payment Step slot -->
<template id="spark-slot-cart-payment-step">
<div class="my-content">
Content here will show in the Cart Payment Step section.
</div>
</template>
<!-- Example code for the Purchase Summary Header slot -->
<template id="spark-slot-purchase-summary-header">
<div class="my-content">
Content here will show in the Purchase Summary Header section.
</div>
</template>
<!-- Example code for the Purchase Summary Footer slot -->
<template id="spark-slot-purchase-summary-footer">
<div class="my-content">
Content here will show in the Purchase Summary Footer section.
</div>
</template>Put the templates in your theme's main layout file (for example layout/theme.liquid on Shopify), or anywhere else that's easy to find and update.
The content can be a line of text, or full HTML with CSS, images and other elements. Only your B2B customers see it:
- Content in a template only shows in its slot. For example, the
spark-slot-my-carttemplate shows in the My Cart. - Templates aren't shown anywhere else on your store, and customers who aren't signed in never see them.
Only change your own slot content
You can only change the elements inside your own slot templates. Don't try to change SparkLayer's own interface elements (the DOM): their structure and selectors change regularly, so any code that relies on them will stop working.
Examples you can use
These examples are for your developer, ready to copy and adapt. The Liquid examples (using {{ }} and {% %}) are for Shopify.
This shows a compact banner with a delivery truck icon, styled to match SparkLayer's interfaces: a white card with a light grey border, a green icon tile and one line of text, for example "Free shipping on orders over $500. To any of your delivery addresses."
Each template has its own <style>, and every class starts with shipping-banner, so the banner doesn't change your theme's styles or SparkLayer's. It uses the interface's own font. Change the amount and the words to suit your store.
<!-- Template element for My Order Interface -->
<template id="spark-slot-my-cart">
<style>
.shipping-banner { display: flex; align-items: center; gap: 10px; margin: 0; padding: 7px 12px 7px 8px; border: 1px solid #d7d5dd; border-radius: 8px; background: #fff; color: #26232f; font: inherit; font-size: 12.5px; line-height: 1.45; text-align: left; }
.shipping-banner__icon { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: #e7f6ee; color: #047857; }
.shipping-banner__icon svg { width: 16px; height: 16px; }
.shipping-banner__text { flex: 1; min-width: 0; margin: 0; color: #6b6577; }
.shipping-banner__text strong { color: #26232f; font-weight: 600; }
</style>
<div class="shipping-banner">
<span class="shipping-banner__icon">
<svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 18V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v11a1 1 0 0 0 1 1h2" /><path d="M15 18H9" /><path d="M19 18h2a1 1 0 0 0 1-1v-3.65a1 1 0 0 0-.22-.62l-3.48-4.35A1 1 0 0 0 17.52 8H14" /><circle cx="17" cy="18" r="2" /><circle cx="7" cy="18" r="2" /></svg>
</span>
<p class="shipping-banner__text"><strong>Free shipping on orders over $500.</strong> To any of your delivery addresses.</p>
</div>
</template>
<!-- Template element for My Account Interface -->
<template id="spark-slot-my-account">
<style>
.shipping-banner { display: flex; align-items: center; gap: 10px; margin: 0; padding: 7px 12px 7px 8px; border: 1px solid #d7d5dd; border-radius: 8px; background: #fff; color: #26232f; font: inherit; font-size: 12.5px; line-height: 1.45; text-align: left; }
.shipping-banner__icon { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: #e7f6ee; color: #047857; }
.shipping-banner__icon svg { width: 16px; height: 16px; }
.shipping-banner__text { flex: 1; min-width: 0; margin: 0; color: #6b6577; }
.shipping-banner__text strong { color: #26232f; font-weight: 600; }
</style>
<div class="shipping-banner">
<span class="shipping-banner__icon">
<svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 18V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v11a1 1 0 0 0 1 1h2" /><path d="M15 18H9" /><path d="M19 18h2a1 1 0 0 0 1-1v-3.65a1 1 0 0 0-.22-.62l-3.48-4.35A1 1 0 0 0 17.52 8H14" /><circle cx="17" cy="18" r="2" /><circle cx="7" cy="18" r="2" /></svg>
</span>
<p class="shipping-banner__text"><strong>Free shipping on orders over $500.</strong> On every order, to any of your delivery addresses.</p>
</div>
</template>
<!-- Template element for Order Complete -->
<template id="spark-slot-order-complete">
<style>
.shipping-banner { display: flex; align-items: center; gap: 10px; margin: 0; padding: 7px 12px 7px 8px; border: 1px solid #d7d5dd; border-radius: 8px; background: #fff; color: #26232f; font: inherit; font-size: 12.5px; line-height: 1.45; text-align: left; }
.shipping-banner__icon { flex: none; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 6px; background: #e7f6ee; color: #047857; }
.shipping-banner__icon svg { width: 16px; height: 16px; }
.shipping-banner__text { flex: 1; min-width: 0; margin: 0; color: #6b6577; }
.shipping-banner__text strong { color: #26232f; font-weight: 600; }
</style>
<div class="shipping-banner">
<span class="shipping-banner__icon">
<svg aria-hidden="true" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 18V6a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2v11a1 1 0 0 0 1 1h2" /><path d="M15 18H9" /><path d="M19 18h2a1 1 0 0 0 1-1v-3.65a1 1 0 0 0-.22-.62l-3.48-4.35A1 1 0 0 0 17.52 8H14" /><circle cx="17" cy="18" r="2" /><circle cx="7" cy="18" r="2" /></svg>
</span>
<p class="shipping-banner__text"><strong>Free shipping on your next order over $500.</strong> To any of your delivery addresses.</p>
</div>
</template>This shows the same compact banner with your own logo in place of the icon, for example to promote a rewards programme: "Earn rewards points on every order you place online."
Replace link-to-your-logo with the full URL of your logo image, and the alt text with your programme's name. The logo is 28px high and keeps its own width, so a wide logo works too. Every class starts with rewards-banner.
<!-- Template element for My Order Interface -->
<template id="spark-slot-my-cart">
<style>
.rewards-banner { display: flex; align-items: center; gap: 10px; margin: 0; padding: 7px 12px 7px 8px; border: 1px solid #d7d5dd; border-radius: 8px; background: #fff; color: #26232f; font: inherit; font-size: 12.5px; line-height: 1.45; text-align: left; }
.rewards-banner__logo { flex: none; display: block; height: 28px; width: auto; }
.rewards-banner__text { flex: 1; min-width: 0; margin: 0; color: #6b6577; }
.rewards-banner__text strong { color: #26232f; font-weight: 600; }
</style>
<div class="rewards-banner">
<img class="rewards-banner__logo" src="link-to-your-logo" alt="Your rewards programme">
<p class="rewards-banner__text"><strong>Earn rewards points</strong> on every order you place online.</p>
</div>
</template>
<!-- Template element for My Account Interface -->
<template id="spark-slot-my-account">
<style>
.rewards-banner { display: flex; align-items: center; gap: 10px; margin: 0; padding: 7px 12px 7px 8px; border: 1px solid #d7d5dd; border-radius: 8px; background: #fff; color: #26232f; font: inherit; font-size: 12.5px; line-height: 1.45; text-align: left; }
.rewards-banner__logo { flex: none; display: block; height: 28px; width: auto; }
.rewards-banner__text { flex: 1; min-width: 0; margin: 0; color: #6b6577; }
.rewards-banner__text strong { color: #26232f; font-weight: 600; }
</style>
<div class="rewards-banner">
<img class="rewards-banner__logo" src="link-to-your-logo" alt="Your rewards programme">
<p class="rewards-banner__text"><strong>Welcome back.</strong> Earn rewards points on every order you place online.</p>
</div>
</template>
<!-- Template element for Order Complete -->
<template id="spark-slot-order-complete">
<style>
.rewards-banner { display: flex; align-items: center; gap: 10px; margin: 0; padding: 7px 12px 7px 8px; border: 1px solid #d7d5dd; border-radius: 8px; background: #fff; color: #26232f; font: inherit; font-size: 12.5px; line-height: 1.45; text-align: left; }
.rewards-banner__logo { flex: none; display: block; height: 28px; width: auto; }
.rewards-banner__text { flex: 1; min-width: 0; margin: 0; color: #6b6577; }
.rewards-banner__text strong { color: #26232f; font-weight: 600; }
</style>
<div class="rewards-banner">
<img class="rewards-banner__logo" src="link-to-your-logo" alt="Your rewards programme">
<p class="rewards-banner__text"><strong>Thanks for your order.</strong> Points from this order will be added to your rewards.</p>
</div>
</template> <!--
You can change the message type using the following
type="success"
type="info"
type="warn"
type="error"
-->
<!-- Template element for My Order Interface-->
<template id="spark-slot-my-cart">
<spark-message
type="success"
title="Title here"
message="Message here">
</spark-message>
</template>
<!-- Template element for My Account Interface-->
<template id="spark-slot-my-account">
<spark-message
type="info"
title="Title here"
message="Message here">
</spark-message>
</template>
<!-- Template element for Order Complete -->
<template id="spark-slot-order-complete">
<spark-message
type="warn"
title="Title here"
message="Message here">
</spark-message>
</template>
<!--
Replace custom.field_name with the metafield namespace and key
-->
<!-- Template element for My Account Interface-->
{% if customer.metafields.custom.field_name %}
<template id="spark-slot-my-account">
Your message here.
You can output a metafield like this
{{ customer.metafields.custom.field_name }}
</template>
{% endif %}
<!-- Template element for My Order Interface-->
<template id="spark-slot-my-cart">
Hello {{ customer.name }}, here's a message for you.
</template>
<!-- Template element for My Account Interface-->
<template id="spark-slot-my-account">
Hello {{ customer.name }}, here's a message for you.
</template>
<!-- Template element for Order Complete -->
<template id="spark-slot-order-complete">
Hello {{ customer.name }}, here's a message for you.
</template>Shopify only
<template id="spark-slot-my-cart">
{% for tag in customer.tags %}
{% if tag == "b2b-group-1" %}
As a Group 1 customer, you qualify for special B2B pricing!
{% elsif tag == "b2b-group-2" %}
As a Group 2 customer, you qualify for special B2B pricing!
{% else %}
Message to show for regular B2B customers
{% endif %}
{% endfor %}
</template>Shopify only
This shows different delivery terms in My Cart depending on the country or Shopify Market (opens in a new tab) the customer is shopping in. That's the country chosen in your store's country selector, or the one Shopify picks for them, not the country of their address.
Use localization.country.iso_code for a country, or localization.market.handle for a market. Customers in any other country or market see nothing in the slot.
{% if localization.country.iso_code == 'GB' %}
<template id="spark-slot-my-cart">
Free UK delivery on orders over £500.
</template>
{% elsif localization.market.handle == 'eu' %}
<template id="spark-slot-my-cart">
Orders to the EU ship from our Rotterdam warehouse within 2 working days.
</template>
{% endif %} <!-- Template element for My Order Interface-->
<template id="spark-slot-my-cart">
<p>Here is a message</p>
<img src="link-to-image" style="max-width: 100%">
</template>
<!-- Template element for My Account Interface-->
<template id="spark-slot-my-account">
<p>Here is a message</p>
<img src="link-to-image" style="max-width: 100%">
</template>
<!-- Template element for Order Complete -->
<template id="spark-slot-order-complete">
<p>Here is a message</p>
<img src="link-to-image" style="max-width: 100%">
</template>This shows a message under a product line in My Cart that refers to the product, for example "MUG-CAT - example-ceramic-mug requires special handling." It uses the product's SKU and slug.
For slots that need different messages or behaviour on each line, use web components to keep each line's state separate, as in the example below.
This slot can read these data- attributes from its parent element, using this.parentNode.dataset:
data-skudata-slugdata-spark-iddata-platform-iddata-item-keydata-custom-attributes: the line's custom attributes as a JSON list ofkey,valueandtype. Read them withJSON.parse(data.customAttributes).
<script>
class LineItemInfo extends HTMLElement {
connectedCallback() {
let data = this.parentNode.dataset;
this.innerHTML = `<p class="line-item-info-messsage">${data.sku} - ${data.slug} requires special handling.</p>`;
}
}
customElements.define('line-item-info', LineItemInfo);
</script>
<template id="spark-slot-my-cart-line-item">
<style>
.line-item-info-messsage {
background: #f5f5f5;
padding: 8px;
border-radius: 4px;
}
</style>
<line-item-info></line-item-info>
</template>As with every slot, only change elements inside your own template, not SparkLayer's own elements.
This shows a message that your own JavaScript chooses each time the slot appears, for example from a geolocation service, a cookie or another app on your store. It works on every platform.
SparkLayer copies the template into the slot each time it shows it, such as when a customer opens My Cart. Scripts inside a template don't run there, so put the logic in a web component defined in your theme, and put the component in the template:
<script>
class MarketMessage extends HTMLElement {
connectedCallback() {
// Replace with however your store knows the customer's country
const country = window.myStore?.country;
this.innerHTML = country === 'US'
? '<p class="market-message">Orders ship from our US warehouse.</p>'
: '<p class="market-message">Orders ship from our UK warehouse.</p>';
}
}
customElements.define('market-message', MarketMessage);
</script>
<template id="spark-slot-my-cart">
<style>
.market-message {
background: #f5f5f5;
padding: 8px;
border-radius: 4px;
}
</style>
<market-message></market-message>
</template>Things to know when writing your component:
- Your theme's CSS doesn't reach slot content, as it shows inside SparkLayer's interface. Put the styles in a
<style>element in the template, as above. - The component can change its own content at any time after it appears, for example when a request it made comes back. Changing the template only affects the next time the slot appears.
- A component that shows nothing still leaves a small gap. To show nothing at all, leave the template out of the page instead.
- Leave the slot turned on, and choose the content in your component. Turning slots on and off from code isn't supported.
The purchase summary slots (spark-slot-purchase-summary-header and spark-slot-purchase-summary-footer) can read these data- attributes about the purchase, using this.parentNode.dataset:
data-spark-id: SparkLayer's ID for the purchase.data-platform-id: your platform's ID for the purchase, if it has one.data-visible-id: the order or quote number the customer sees.data-custom-fields: the purchase's custom fields as a JSON list ofname,valueandtype. Read them withJSON.parse(data.customFields).
For the line-item slot's attributes, see Show a message at a cart line-item level.
Found a good use for custom slots? Tell our team at product@sparklayer.io.
FAQs
Yes. Slot content is code in your theme, so your developer can wrap the template in a condition on the customer's tags. A customer group's tag starts with b2b-, such as b2b-vip. For example, this shows a downloads link in My Account only to customers tagged b2b-group-1, and other customers see nothing in the slot:
{% if customer.tags contains 'b2b-group-1' %}
<template id="spark-slot-my-account">
<a href="/pages/trade-downloads">Download your price list and product sheets</a>
</template>
{% endif %}To show different content to each group instead, see Show a message based on the Shopify tag assigned to a customer. These examples use Liquid, so they're for Shopify.
Yes. There's no SparkLayer setting or hook for it, but a web component in the template can choose what to show each time the slot appears, using any JavaScript your theme has. See Show a message chosen with JavaScript. On Shopify, Liquid is simpler for content that depends on the customer's country or market: see Show a message based on the customer's country or market.
Last updated