Skip to main content

Slider Example

Handlebars Slider Template for a Slider

Slider Example internet plans

<div class="slider-container">
{{#each items}}
<div class="slider-card" style="display:none;">
<img
class="slider-image"
src="{{image.url}}"
alt="TV Package Image for {{packageName}}"
/>
<div class="slider-content">
<div class="slider-top-row">
<div class="slider-channels">{{internetSpeed}}</div>
<div class="slider-channels-label">Channels</div>
</div>
<div class="slider-package-name">{{packageName}}</div>
<div class="slider-price-section">
<span class="slider-price">${{packagePrice}}</span>
<span class="slider-price-unit">/mo</span>
<button
class="slider-cta-btn"
onclick='ai12zBot.sendMessage("Select this Plan: {{packageName}}", "Select Plan")'
>
Select Plan &rarr;
</button>
</div>
<div class="slider-description-box">{{{packageDescription}}}</div>
</div>
</div>
{{/each}}
<div class="slider-controls">
<button class="slider-arrow" onclick="prevSlide()" aria-label="Previous">
&#8592;
</button>
<div class="slider-dots">
{{#each items}}
<button class="slider-dot" onclick="goToSlide({{@index}})"></button>
{{/each}}
</div>
<button class="slider-arrow" onclick="nextSlide()" aria-label="Next">
&#8594;
</button>
</div>
</div>

Javascript for a slider in the AI Handlebar

// Custom Handlebars Helper for Safe HTML (if needed)
window.Handlebars.registerHelper("safeHTML", function (text) {
return new window.Handlebars.SafeString(text)
})

// Slider Logic for ai12z Shadow DOM
// Place this in the Script tab of the control
window.sliderIndex = 0
function showSlide(n) {
var cards = carousel?.shadowRoot?.querySelectorAll(".slider-card") || []
if (!cards.length) return
n = (n + cards.length) % cards.length
window.sliderIndex = n
cards.forEach(function (card, idx) {
card.style.display = idx === n ? "block" : "none"
})
// Update dots
var dots = carousel?.shadowRoot?.querySelectorAll(".slider-dot") || []
dots.forEach(function (dot, idx) {
dot.classList.toggle("active", idx === n)
})
}
function nextSlide() {
showSlide(window.sliderIndex + 1)
}
function prevSlide() {
showSlide(window.sliderIndex - 1)
}
function goToSlide(idx) {
showSlide(idx)
}

// On render, show the first slide
setTimeout(function () {
showSlide(0)
}, 100)

Style for a slider in the AI Handlebar

.slider-container {
width: 100%;
max-width: 420px;
margin: 0 auto;
position: relative;
background: #f7fafc;
border-radius: 2rem;
box-shadow:
0 8px 32px 0 rgba(52, 78, 134, 0.13),
0 1.5px 8px 0 rgba(40, 30, 70, 0.04);
padding: 0 0 2.5rem 0;
}
.slider-card {
display: none;
background: #fff;
border-radius: 2rem;
overflow: hidden;
box-shadow:
0 8px 32px 0 rgba(52, 78, 134, 0.13),
0 1.5px 8px 0 rgba(40, 30, 70, 0.04);
padding-bottom: 1.2rem;
margin: 0 auto;
max-width: 420px;
}
.slider-card.active {
display: block;
}
.slider-image {
width: 100%;
height: 180px;
object-fit: cover;
border-top-left-radius: 2rem;
border-top-right-radius: 2rem;
background: #e5e7eb;
}
.slider-content {
padding: 1.2rem 1.2rem 0.7rem 1.2rem;
display: flex;
flex-direction: column;
align-items: center;
}
.slider-top-row {
display: flex;
align-items: flex-end;
justify-content: center;
gap: 0.7rem;
margin-bottom: 0.2rem;
}
.slider-channels {
font-size: 2.1rem;
font-weight: 800;
color: #22223b;
margin-bottom: 0;
text-align: center;
line-height: 1.1;
}
.slider-channels-label {
font-size: 1.08rem;
color: #64748b;
margin-bottom: 0;
margin-left: 0.5rem;
text-align: left;
font-weight: 500;
letter-spacing: 0.01em;
}
.slider-package-name {
font-size: 1.13rem;
font-weight: 700;
color: #2d7be5;
margin-bottom: 0.7rem;
text-align: center;
margin-top: 0.1rem;
cursor: pointer;
text-decoration: underline;
}
.slider-price-section {
background: #f1f5f9;
border-radius: 1.1rem;
padding: 0.7rem 0.5rem 0.7rem 0.5rem;
margin-bottom: 0.7rem;
width: 100%;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
gap: 1.2rem;
min-height: 64px;
}
.slider-price {
font-size: 2.1rem;
font-weight: 800;
color: #22223b;
margin-bottom: 0;
margin-right: 0.2rem;
line-height: 1.1;
}
.slider-price-unit {
font-size: 1.1rem;
color: #64748b;
margin-left: 0.1rem;
margin-right: 0.7rem;
font-weight: 500;
}
.slider-cta-btn {
background: linear-gradient(90deg, #2d7be5 0%, #1e40af 100%);
color: #fff;
font-weight: 700;
font-size: 1.1rem;
border: none;
border-radius: 2em;
padding: 0.7em 2.1em;
margin: 0;
cursor: pointer;
box-shadow: 0 4px 16px rgba(45, 123, 229, 0.13);
transition:
background 0.18s,
box-shadow 0.14s,
transform 0.12s;
display: flex;
align-items: center;
justify-content: center;
min-height: 44px;
}
.slider-cta-btn:hover,
.slider-cta-btn:focus {
background: linear-gradient(90deg, #1e40af 0%, #2d7be5 100%);
box-shadow: 0 8px 24px rgba(45, 123, 229, 0.18);
transform: scale(1.04);
}
.slider-description-box {
background: #f9fafb;
border-radius: 1.1rem;
padding: 1.1rem 1.1rem 0.7rem 1.1rem;
margin-top: 0.3rem;
width: 100%;
font-size: 1.08rem;
color: #22223b;
box-shadow: 0 2px 8px rgba(52, 78, 134, 0.06);
}
.slider-description-box ul {
margin: 0.7em 0 0.7em 1.2em;
padding: 0;
}
.slider-description-box li {
margin-bottom: 0.3em;
font-size: 1.05em;
}
.slider-description-box b,
.slider-description-box strong {
color: #2d7be5;
}
.slider-channel-logos {
display: flex;
align-items: center;
gap: 1.2rem;
margin-top: 0.7rem;
margin-bottom: 0.2rem;
}
.slider-channel-logos img {
height: 32px;
width: auto;
background: #fff;
border-radius: 0.5em;
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.07);
padding: 0.2em 0.5em;
}
.slider-controls {
display: flex;
justify-content: center;
align-items: center;
gap: 1.2rem;
margin-top: 1.2rem;
}
.slider-arrow {
background: #e5e7eb;
border: none;
border-radius: 50%;
width: 38px;
height: 38px;
display: flex;
align-items: center;
justify-content: center;
font-size: 1.5rem;
color: #2d7be5;
cursor: pointer;
transition:
background 0.16s,
color 0.16s;
}
.slider-arrow:hover,
.slider-arrow:focus {
background: #2d7be5;
color: #fff;
}
.slider-dots {
display: flex;
gap: 0.6rem;
margin-top: 0.5rem;
}
.slider-dot {
width: 12px;
height: 12px;
border-radius: 50%;
background: #cbd5e1;
border: none;
cursor: pointer;
transition: background 0.18s;
}
.slider-dot.active {
background: #2d7be5;
}
@media (max-width: 600px) {
.slider-container,
.slider-card {
max-width: 99vw;
border-radius: 1.1rem;
}
.slider-image {
height: 120px;
border-radius: 1.1rem 1.1rem 0 0;
}
.slider-content {
padding: 0.7rem 0.5rem 0.5rem 0.5rem;
}
.slider-description-box {
padding: 0.7rem 0.5rem 0.5rem 0.5rem;
}
.slider-price-section {
min-height: 48px;
padding: 0.5rem 0.2rem 0.5rem 0.2rem;
}
}

JSON

{
"items": [
{
"image": {
"url": "https://cdn-ca.aglty.io/westman-communications/Attachments/NewItems/TVPack_Image_CasualViewerSlider_20250103120352.jpg"
},
"internetSpeed": "35",
"packageDescription": "<p>The essentials, including kids' programming, The Weather Network, and major networks for casual viewing.</p>\r\n<ul>\r\n<li>\r\n<p>For the <strong>casual viewer</strong></p>\r\n</li>\r\n<li>\r\n<p><strong></strong><strong>Free</strong> GO&nbsp;Apps</p>\r\n</li>\r\n<li>\r\n<p><strong>Free</strong> Professional Installation&nbsp;</p>\r\n</li>\r\n</ul>\r\n<p style=\"font-size: 12px;\"><em>&nbsp;</em></p>\r\n<p style=\"font-size: 12px;\"><em>Includes channels like:</em></p>\r\n<p style=\"font-size: 12px;\"><em>&nbsp;</em><em> &nbsp; <img src=\"https://cdn-ca.aglty.io/westman-communications/channel-logos/CTV_Logo.svg\" width=\"91\" height=\"29\">&nbsp; &nbsp; <img src=\"https://cdn-ca.aglty.io/westman-communications/channel-logos/TWN_Logo.svg\" width=\"134\" height=\"32\">&nbsp; &nbsp;<img src=\"https://cdn-ca.aglty.io/westman-communications/channel-logos/Global_Winnipeg.svg\" width=\"76\" height=\"38\"></em></p>",
"packageName": "Lite Choice",
"packagePrice": "24.95",
"packageTerms": "1"
}
]
}