Template & helper reference
EJS basics, the data your templates receive, every helper, animation attributes, and the markup for forms, cookie consent and selling online.
Templates are written in EJS and styled with Tailwind by default. This page lists everything a template can use. The same reference is built into Site Builder, next to your code.
- Rendering and content helpers
- What it does and its arguments
- Copy-ready examples
EJS basics#
| Tag | Does |
|---|---|
<%= value %> |
Outputs text, HTML-escaped |
<%- value %> |
Outputs raw HTML: use it for helpers that return markup |
<% code %> |
Runs JavaScript (loops, conditions, variables) with no output |
<%# comment %> |
A comment, left out of the page |
Template variables#
| Variable | What it holds |
|---|---|
item |
The page, entry or block being rendered |
pages |
All pages |
entries |
All entries, by handle |
images |
All media images |
options |
All option sets |
main |
In the layout only: the rendered page |
Every page record also has:
| Field | Holds |
|---|---|
_path |
Its URL path, like /menu/country-sourdough |
_slug |
Its slug, for collection records: country-sourdough |
_meta.updated_at |
When it was last changed |
<h1><%= item.title %></h1>
<p>Updated <%= new Date(item._meta.updated_at).toLocaleDateString() %></p>
<%- main %> <!-- in the layout -->
Content helpers#
| Helper | Returns |
|---|---|
getPage(path) |
One page, by its exact path: getPage('/about') |
getPages(path, { collection? }) |
All pages under a path. { collection: true } returns only collection records. Always a path, like '/blog' |
getEntry(handle) |
An entry. A single entry returns an object; a collection returns an array. The + is optional: getEntry('testimonials') and getEntry('testimonials+') are the same |
getSlugs(path) |
The slugs of a collection's pages |
getImage(handle) |
A media image by handle |
getVideo(handle) |
A media video by handle |
getOptions(handle) |
An option set, as [{ label, value }] |
getContent(query?) |
All content, or what a JMESPath query selects |
path(page) |
A page's URL path |
url(path | page?) |
A full URL on your site: url('/menu') gives https://acmebakery.com/menu. With nothing passed, your site's address |
<% const posts = getPages('/blog', { collection: true }); %>
<ul>
<% posts.forEach(post => { %>
<li><a href="<%= path(post) %>"><%= post.title %></a></li>
<% }) %>
</ul>
<% getEntry('testimonials').forEach(t => { %>
<blockquote><%= t.quote %> · <%= t.name %></blockquote>
<% }) %>
<% const featured = getContent('pages[?featured==`true`]'); %>
Rendering helpers#
| Helper | Does |
|---|---|
render(value, separator?) |
Renders a block, or a list of blocks (a Stack or Collection field), each with its own template |
remark(markdown, opts?) |
Turns Markdown into HTML |
<%- render(item.sections) %>
<div class="prose"><%- remark(item.body) %></div>
Markdown with remark()#
Use remark() for every Markdown field. On top of standard Markdown (tables, task lists, footnotes) it renders:
- Code blocks, highlighted when the site builds. Choose the colours with
codeTheme:github-dark(the default),githubfor light code blocks,atom-one-dark,base16/draculaand more. One theme per page - Math:
$e^{i\pi}+1=0$inline, or$$…$$on its own lines. Prices like "5 to $10" stay text; write `\` for a dollar sign that must stay literal - Mermaid diagrams in a
```mermaidblock, drawn when the site builds and matched to your page's colours. Set--pele-*CSS variables, like--pele-accentand--pele-surface, for brand colours
Only the styles and scripts the Markdown needs are added to the page, so don't load your own highlighter or math library.
<%- remark(item.recipe, { codeTheme: 'github' }) %>
Images, maps and video#
| Helper | Returns |
|---|---|
src(image, attr) |
An optimised image URL |
img(image, attr) |
An <img> element, with alt text from the image |
picture(image, attr) |
A <picture> element with light and dark versions |
svg(image, attr?) |
The SVG inline, so you can style it with CSS. Also takes icons: 'iconify:lucide:arrow-right' |
Image attributes are "WxH", or { w, h, size, fit, type, class, style }. type is a format like webp or avif; fit is cover, contain, fill, inside or outside.
<%- img(item.hero, { w: 1600, h: 900, fit: 'cover', class: 'w-full rounded-xl' }) %>
<img src="<%- src(item.photo, '800x600') %>" alt="">
<%- img('cms:logo', '120x40') %> <!-- a media library image by handle -->
<%- svg('iconify:lucide:wheat', { class: 'size-6 text-amber-700' }) %>
Location fields work with the same helpers:
| Helper | Returns |
|---|---|
src(location, attr) / img(location, attr) |
A static map |
embed(location, attr?) |
A Google Maps embed |
markers(location) |
[{ lat, lng }] |
Map attributes are "WxH", or { w, h, size, zoom, maptype, scale, class, style }.
Video fields render with embed():
<%- embed(item.intro_video) %>
<%- embed(item.intro_video, { autoplay: true, muted: true, loop: true }) %>
<%- embed(getVideo('bakery-tour'), '1280x720') %>
Video attributes are "WxH", or { w, h, size, autoplay, muted, loop, preload, t, class, style }. Most browsers only autoplay a video that is also muted.
Files#
A File field gives you:
{ name, url, size, type, ext } // e.g. "Catering menu", a download URL, bytes, "application/pdf", "pdf"
An empty File field is null, so check for it first:
<% if (item.menu_pdf) { %>
<a href="<%= item.menu_pdf.url %>" download>
<%= item.menu_pdf.name %> (<%= item.menu_pdf.ext.toUpperCase() %>)
</a>
<% } %>
Head & meta helpers#
Call these from any template: the page's, a block's or the layout. What they add goes in the page's <head>, with duplicates removed.
| Helper | Adds |
|---|---|
title(text) |
The page <title> |
meta(attrs) |
A <meta> tag |
link(value, order?) |
A <link>: a stylesheet URL, an object like a canonical link, or a library's CSS |
script(value, order?) |
A <script>: a .js URL, inline code, an object of attributes, or a library |
style(css, order?) |
An inline <style> |
<% title(item.title + ' | Acme Bakery') %>
<% meta({ name: 'description', content: item.seo?.description }) %>
<% link({ rel: 'canonical', href: url(item) }) %>
<% script('/js/menu-filter.js') %>
<% script({ type: 'module', src: '/js/site.js' }) %>
Predefined libraries#
Pass a library's name to script() or link(), and its scripts and styles are added once, from fixed versions:
motion · gsap (with ScrollTrigger) · alpinejs · swiper · splide · animejs · chartjs · threejs · lottie · typedjs · htmx · vanilla-tilt · aos (older sites)
<% script('swiper') %>
<% script('threejs') %>
<% script({ type: 'module', content: `import * as THREE from 'three';` }) %>
Animation#
Add data-motion attributes to your HTML and elements animate as they scroll into view, with no scripts to load. Animation is only loaded on pages that use it, and visitors who turn on reduced motion in their device settings see everything in place, without movement.
<h2 data-motion="fade-up">Fresh every morning.</h2>
<div data-motion-stagger="90" class="grid gap-6 md:grid-cols-3">
<article data-motion="fade-up">…</article>
<article data-motion="fade-up">…</article>
<article data-motion="fade-up">…</article>
</div>
Reveals#
data-motion="<preset>" plays once, when the element comes into view.
| Preset | Effect |
|---|---|
fade · fade-up · fade-down · fade-left · fade-right |
Fades in, optionally moving into place |
zoom-in · zoom-out |
Fades in while growing or shrinking to size |
blur-in |
Fades in from blurred |
pop |
Springs in: good for a button or badge |
flip-up · flip-down · flip-left · flip-right |
Turns into place in 3D |
reveal-up · reveal-down · reveal-left · reveal-right |
Wipes into view: good for images |
draw |
Draws an SVG's lines |
For your own starting point, write it instead of a preset, like data-motion="y: 80; rotate: -6; opacity: 0".
Fine-tune a reveal with:
| Attribute | Default |
|---|---|
data-motion-delay |
0 (milliseconds) |
data-motion-duration |
600 (milliseconds) |
data-motion-easing |
A soft ease-out. Also linear, ease-in-out, spring, bounce and more |
data-motion-distance |
24 (px): how far fade-* presets travel |
More effects#
| Attribute | Does | Example |
|---|---|---|
data-motion-stagger="80" |
On a container: its children's reveals play one after another | Service cards |
data-motion-text="words" or "chars" |
Reveals a heading word by word, or letter by letter | Hero headline |
data-motion-counter |
Counts up to the number in the element, keeping its format, like 1,250+ |
Stats band |
data-motion-parallax="0.2" |
Drifts against the scroll | Hero background |
data-motion-scroll="scale: .85 1" |
Ties a change to the scrollbar, forwards and back. Set when with data-motion-scroll-range: enter, exit, cover, pin or page |
Product shot that grows; a reading progress bar |
data-motion-horizontal |
Scrolling down slides a row of items sideways | Portfolio gallery |
data-motion-hover="tilt" or "magnetic" |
Tilts toward the pointer, or leans toward it | Cards; a call-to-action button |
data-motion-marquee="40" |
An endless ticker, at a speed in pixels per second | Logo strip |
A reading progress bar, in the layout:
<div data-motion-scroll="scaleX: 0 1" data-motion-scroll-range="page"
class="fixed inset-x-0 top-0 z-50 h-1 origin-left bg-amber-600"></div>
Good to know:
- Don't hide animated elements yourself with
opacity-0orinvisible. They're hidden until they animate, and every animation ends on your own styles - One effect per element for parallax, scroll and hover. Wrap one element in another to combine them
- Use it sparingly: one hero entrance, and a couple of reveal styles per page
Your own animation code#
For effects the attributes can't do, like a menu that opens in sequence or a header that hides as you scroll down, load Motion and write your own script:
<% script('motion') %>
<% script({ type: 'module', src: '/js/site.js' }) %>
// /js/site.js
import { animate, scroll, inView, stagger } from 'motion';
if (!matchMedia('(prefers-reduced-motion: reduce)').matches) {
document.querySelector('.js-menu-open').addEventListener('click', () => {
animate('.js-menu a', { opacity: [0, 1], transform: ['translateX(-8px)', 'none'] },
{ delay: stagger(0.05) });
});
}
- Load
script('motion')before your own script, and import from'motion' - Times are in seconds here, unlike the attributes' milliseconds
- Keep entrance animations on
data-motion, and don't animate an element that already has adata-motionattribute
See motion.dev for the full Motion API.
Forms and bookings#
Add data-sleekcms with your form's name to any <form>. Submissions arrive in your Inbox:
<form data-sleekcms="quote-request">
<input name="name" required>
<input name="email" type="email" required>
<textarea name="message"></textarea>
<button>Send</button>
</form>
For a booking form, include an email field and an <input type="datetime-local">. Visitors get a picker showing your available times:
<form data-sleekcms="cake-consultation">
<input name="email" type="email" required>
<input name="slot" type="datetime-local" required>
<button>Book</button>
</form>
See Forms for field types and settings.
Cookie consent#
With the cookie banner turned on in Analytics & cookie consent, tag each script or embed that needs consent with a category. It doesn't run until the visitor accepts that category. Analytics you set up in Analytics is tagged for you.
<% script({ src: 'https://widget.example.com/reviews.js', 'data-sleekcms-consent': 'marketing' }) %>
<% script({ content: "fbq('track', 'PageView');", 'data-sleekcms-consent': 'analytics' }) %>
<iframe data-sleekcms-consent="marketing" src="https://www.youtube.com/embed/VIDEO_ID" allowfullscreen></iframe>
- Categories are yours to name, like
analytics,marketingorpersonalization. The banner lists each one it finds on your site.necessary,preferencesandconfigare reserved - Embeds show a "click to load" placeholder until the visitor accepts
- A "Cookie settings" link lets visitors change their choice later. Put one in your footer:
<a data-sleekcms-consent href="#">Cookie settings</a>
Customising the banner#
Add one empty element to your layout. It's read when the site builds and isn't shown on the page:
<div data-sleekcms-consent data-position="bottom-right" data-theme="light" data-policy-url="/privacy"></div>
| Attribute | Values | Default |
|---|---|---|
data-position |
bottom, bottom-left, bottom-right, modal |
bottom |
data-theme |
light, dark, auto |
auto |
data-policy-url |
Your privacy or cookie policy page | No link |
data-locale |
Banner language: en, de, fr, es, it, nl, pt, pl |
From the page, then the browser |
data-message |
The banner text | Built-in text |
data-accept-label · data-decline-label |
Button text | "Accept" · "Decline" |
Match it to your brand with CSS variables:
:root {
--sleek-consent-bg: #3b2416;
--sleek-consent-text: #fff8f0;
--sleek-consent-accent: #d97706;
--sleek-consent-on-accent: #ffffff; /* text on the accent button */
--sleek-consent-radius: 12px;
}
Consent in your own scripts#
sleekcms.consent.get(); // { necessary: true, analytics: true, marketing: false }
sleekcms.consent.open(); // open the preferences panel
sleekcms.consent.on('change', (c) => { }); // runs whenever choices change
Code that runs before the banner loads can listen for the sleekcms:consent event on window instead.
Selling online#
Three ways to take orders, each set up with one line in your layout:
| SleekSite Store | Snipcart checkout | WhatsApp order | |
|---|---|---|---|
| What happens | Built-in shop: product pages, cart, Stripe checkout, stock and orders in Store | A cart, card payment and customer accounts | Visitors build a selection and send it to you as one WhatsApp message |
| Fits | Shops selling goods, downloads or services at set prices, donations and invoice payments | Shops already on Snipcart | Restaurants, bakers, caterers, salons, trades: anything you confirm or quote |
| You need | A Stripe account (test mode until you connect it) | A Snipcart account and payment gateway | A WhatsApp number |
Use one of them on a site. Asking the AI Assistant to "add online ordering" sets up either one for you.
SleekSite Store#
Turn the store on in Manage Site → E-Commerce, then add this once in your layout's <body>:
<%- storefront() %>
Place regions where the store should render: <div data-store-grid></div> on /shop, <div data-store-product></div> on /product, <div data-store-checkout></div> on /checkout and <div data-store-order></div> on /order/complete, plus <a href="/shop" data-store-open>Cart <span data-store-count></span></a> in your header. See Store templates for product data in views, product fields and custom product pages, and Store & e-commerce for running the store.
Snipcart checkout#
Keep your Snipcart public API key in a settings entry, then add this at the end of <body> in your layout:
<%- snipcart(getEntry('settings')?.snipcart_key) %>
That loads Snipcart's cart and checkout. Optionally, set the currency: snipcart(key, { currency: 'eur' }). Then add buy buttons and a cart button with Snipcart's usual markup:
<button class="snipcart-add-item"
data-item-id="<%= item._slug %>"
data-item-name="<%= item.title %>"
data-item-price="<%= Number(item.price).toFixed(2) %>"
data-item-url="<%= path(item) %>"
data-item-image="<%- src(item.image, '600x600') %>">
Add to cart
</button>
<button class="snipcart-checkout">Cart <span class="snipcart-items-count"></span></button>
<button class="snipcart-customer-signin">Sign in</button>
data-item-urlis the product's own page, and that page must have the same buy button: Snipcart checks it to validate orders- For a one-off item, add
data-item-max-quantity="1"
ImportantWithout a key of your own, the store runs in Snipcart's test mode: orders are tests and no payment is taken. To take real payments, create a Snipcart account, put your public API key in the settings entry, and set up your payment gateway in Snipcart.
WhatsApp order#
Keep your WhatsApp number in a settings entry as digits only, with the country code and no +, like 14155550123. Then add this at the end of <body> in your layout:
<%- whatsappCart(getEntry('settings')?.whatsapp_number, { currency: 'USD' }) %>
That adds an order drawer. Visitors add items from your pages, review them, and send the list to you on WhatsApp. It's a request, not a payment: you confirm prices and availability with the customer. Add a button for each item:
<button data-wa-add
data-wa-id="<%= item._slug %>"
data-wa-name="<%= item.title %>"
data-wa-price="<%= item.price %>"
data-wa-qty="multi">
Add to order
</button>
| Attribute | Values |
|---|---|
data-wa-id |
A unique id, like item._slug |
data-wa-name |
The name you'll read in the message |
data-wa-price |
The price. Leave it out for items priced on request |
data-wa-price-mode |
fixed (a set price) · from (a starting price, like "From $75") · request ("Price on request") |
data-wa-qty |
single (the default) for services and one-off items · multi for things bought by quantity, like loaves |
data-wa-currency |
Overrides the layout's currency for this item |
Add an order button to your header, or a floating one appears:
<button data-wa-open>Order <span data-wa-count></span></button>
whatsappCart() options: currency, locale, title, intro, openLabel, sendLabel, empty, and float: false to hide the floating button. The selection is saved in the visitor's browser, so it's still there when they come back.