Quick Start - Basket Summary
Web Components are a group of modern browser technologies which allow you to define custom HTML elements and their functionality.
At Spektrix, we are providing them to allow you to ship units of business logic to your clients’ pages without having to write any Javascript (if you don't want to).
There are 4 steps* to using a Spektrix Web Component on your client's web site:
- Load the polyfills
- Load the javascript that defines the Web Component
- Add the Web Component to the markup
- Write the rest of the markup within it.
*Before you do any of this, please ensure that the domain from which you will be serving pages using Web Components is added in Domain Specific Config in your client’s Spektrix system. If you are already using Spektrix APIs or iframes then you probably have this set up already.
Let's use the <spektrix-basket-summary>
component as an example...
Step 1: Load the polyfills
Web Components are still quite a new technology; this code will help them work in older browsers.
Between the
<head>
tags of your page, paste in the following code:
<script src="https://webcomponents.spektrix.com/stable/webcomponents-loader.js"></script>
Step 2: Load the javascript that defines the Web Component
When building a web page, we can use elements like <button>
without any setup because they're already baked into the browser. The Spektrix Web Components add new elements into the browser, and to do that we have to load a bit more javascript on every page where they are used.
Copy and paste the below code into the head, below the polyfill added in step 1:
<script src="https://webcomponents.spektrix.com/stable/spektrix-component-loader.js" data-components="spektrix-basket-summary" async></script>
If you intend to use multiple components on the same page, you can load them all at once by adding them as a comma separated list in the data-components
attribute.
<script src="https://webcomponents.spektrix.com/stable/spektrix-component-loader.js" data-components="spektrix-basket-summary,spektrix-merchandise" async></script>
Step 3: Add the Web Component to the markup
We're nearly there! Now we just need to add the component to the web page and do a little configuration...
Paste the below into the markup between your
<body>
tags:
<spektrix-basket-summary client-name="{client-name}" custom-domain="{custom-domain}">
</spektrix-basket-summary>
Now it's in the markup, you just have to add in the client name and custom domain (if using).
Client name
You can find your client name from either Spektrix Support, or if the venue is a new client, from their Spektrix Project Manager. If you are already working with this client and have previously embedded a Spektrix iframe you can find the client name in an iframe URL, eg:
https://system.spektrix.com/thetheatre/website/eventlist.aspx
In the above URL, "thetheatre" is the client name.
Add the client name into the client-name attribute as follows:
<spektrix-basket-summary client-name="thetheatre" custom-domain="{custom-domain}">
</spektrix-basket-summary>
Custom domain
If a client is making use of a custom domain, the custom-domain
attribute should be populated with this value.
If a client is using custom domains, a URL like the following would open the event list:
https://tickets.thetheatre.org/thetheatre/website/eventlist.aspx
(in this case the custom domain part would be tickets.thetheatre.org
)
If a client is not using a custom domain, this attribute can be omitted.
<spektrix-basket-summary client-name="thetheatre" custom-domain="tickets.thetheatre.org">
</spektrix-basket-summary>
Step 4: Write the rest of your markup within it
The component itself contains the functionality to determine what is in the user's basket. You unlock that functionality by placing your own markup within it.
Try pasting the below in between your
<spektrix-basket-summary>
tags…
<span data-basket-item-count></span> item(s)
<br />
Discount:
<span data-basket-summary-currency></span>
<span data-basket-summary-discount-total></span>
<br />
Total:
<span data-basket-summary-currency></span>
<span data-basket-summary-basket-total></span>
The functionality of the component is unlocked by custom attributes placed on the elements. To achieve the functionality you see an element performing in the example markup above, add in another element and put the same “data-” attribute on it. Experimenting in this manner is a good way to start understanding how best to work with Spektrix Web Components.
Full details of the attributes and what they do can be found in the full documentation.