Edit your Store's template
Change every page of your Store in one file of HTML and CSS, by hand or with an AI chat, see each page as you type, and publish when it is right.
Your Store's pages are drawn from one file: the template. It holds the part every page shares (the header, the footer, the styles) and a part for each kind of page (the home page, a Collection, a product, the Cart, Checkout and your Store pages). You can change anything in it, by hand or by pasting it into an AI chat. Magpie draws buying, the Cart and Checkout itself, so they keep working whatever the template looks like.
Editing the template
- In Store, open the Storefront tab, which opens on Design, then Edit code.
- The editor opens your Store's current design as a draft: the file on the left, the page as buyers will see it on the right. Choose which page to see in Preview, and Desktop or Phone for its width.
- Type in the file. The draft saves as you type and the preview follows a moment later. Buyers do not see the draft.
- Under the file, Check lists anything that would stop the template being published, each with its line. Choose one to go to that line.
- Choose Publish. Your Store uses the template at once; the message has Undo, which puts back what buyers saw before.
Each template you publish is kept. History… in More lists them; Edit this version puts one back in the draft. Download template saves the draft as a file. Start again from a design… replaces the draft with one of Magpie's designs.
Your template, at the top of Design, always shows the design your Store is on. After you choose one of Magpie's designs, it offers Use your earlier template to go back to the one you published.
Changing it with an AI chat
Choose Ask an AI chat… in the editor. Choose what the prompt includes:
- Change what I have: the prompt ends with your draft, the whole file. Tell the chat what to change; it changes that and keeps the rest.
- Start fresh: only this format. The chat makes something new.
Copy the prompt, paste it into the chat, say what you want, and paste its answer into the box. Use this template makes it the draft, and the preview and the check follow. If the check finds something, paste its message back into the chat: it names the line and what to change.
How the file is laid out
<!DOCTYPE html>
<html lang="{{ page.language }}">
<head>
{{ head() }}
<style> … your styles … </style>
</head>
<body>
<header> … the Store's name, menu and Cart … </header>
<main id="sf-content">{% content %}</main>
<footer> … </footer>
{{ scripts() }}
</body>
</html>
{% page "home" %} … the home page … {% endpage %}
{% page "collection" %} … a Collection's page … {% endpage %}
{% page "product" %} … a product's page … {% endpage %}
head()goes inside<head>: it adds the page's title, what search engines and shared links read, and Magpie's styles for its parts. Your styles come after it, so they win.{% content %}is where each page is drawn.scripts()goes just before</body>: the gallery, the Cart and Checkout need it.- The pages are
home,collection,product,cart,checkout,gift_card(checking a gift card's balance),plan_checkout(paying in instalments) andpage(a Store page such as About).home,collectionandproductmust be there; for the others, Magpie draws its own part inside your shared part when you leave the page out. {% sections "video", "lookbook", "story", "quotes", "spotlight", "newsletter", "visit", "promotion" %}, once, before the pages, names the kinds of section from Home page the file draws (see Sections on your Store's home page). On the home page,sections()gives the ones that are filled in and shown, in the seller's order, andsection(item)draws one with Magpie's markup, which your styles change. A kind the file leaves out stays on Home page, marked as not shown.- Magpie adds the page's own classes to
<body>(storefront-page,storefront-productand the like) and puts its bars, such as the draft Store's Preview bar, at the top of the page itself.
The template language
The file is HTML and CSS, with Twig's syntax for what changes from page to page:
{{ product.title }}prints a value, made safe for HTML.{% if store.announcement %} … {% endif %}shows something only when it is there;{% else %}and{% elseif %}work too.{% for product in products %} … {% endfor %}repeats something for each one;loop.indexcounts from 1 andloop.lastis true on the last.{% set heading = "Our shop" %}names a value to use later.{% macro card(product) %} … {% endmacro %}writes a piece once, to draw it with{{ _self.card(product) }}wherever it is needed.- A comment starts with
{#and ends with#}; it is never shown.
Filters change a value: {{ store.name|upper }}, {{ products|length }},
{{ product.description|default("No description") }}. You can use escape,
upper, lower, capitalize, title, trim, length, default, join,
slice, first, last, replace, striptags, nl2br, round, abs,
date, split, reverse, sort, batch, url_encode, keys, merge,
column, filter, map, spaceless and money. Tests: is defined,
is empty, is even, is odd, is null, is iterable, is same as,
is divisible by.
A template cannot run scripts, load another file or reach anything but what
is listed below. There are no ranges such as 1..5: loop over a list instead.
What every page can read
| Name | What it is |
|---|---|
store |
.name, .url, .description, .announcement, .contactEmail, .shipsFrom (a country's name), .currency, .shippingPolicy, .returnsPolicy, .wholesaleUrl (when the Store takes wholesale requests), .isPreview, and .logo and .cover, each with .url, .thumbnailUrl and .alt |
menu |
The Store's menu (Storefront › Menu): All products and the Store's Collections and categories that have products, or the links the seller chose. Each link's .title, .url and .current |
footerPages |
The Store's published pages, then the Shipping and returns and Contact pages Magpie writes: each .title and .url |
cart |
.count and .url |
collections |
Each Collection's .title, .slug, .url, .description and .current |
page |
.type (home, product …) and .language |
look |
The colours and fonts chosen on Design: look.colours.bg, .surface, .media, .text, .muted, .faint, .error, .line, .lineDark, .accent and .onAccent, and look.fonts.heading and look.fonts.body |
Magpie's designs write look into the --sf-… colour and font variables at
the top of their styles, so the Colours and Fonts cards on Design keep
working. Write your own values there to fix them.
On the home and Collection pages:
| Name | What it is |
|---|---|
products |
The products on this page of the list, as product cards |
search |
.query (what was searched for), .filtersActive, and .viewAllUrl |
pagination |
.page, .previousUrl and .nextUrl, or nothing when the list fits on one page |
collection |
On a Collection's or category's page: .title, .slug, .url, .description, .kind (collection or category) and .image (.url, .alt, .width, .height and .focus, the part its seller chose to show, for object-position) |
On a product's page, product is a product card with .slug, .images (each
.url, .thumbnailUrl and .alt), .compareAtPrice (the price before a
sale), .specs (each .name and .value), .bundleParts (each .quantity
and .title), .sizeChart (rows of cells, the first row the headings),
.sizeChartUnit (cm or in for one of your Store's size charts),
.reviewCount, .reviewAverage, .stars (0 to 5) and .wholesale (a
wholesale buyer's note). related lists the products you chose to go with it.
On a Store page, storePage.title and storePage.body (its text, as HTML).
A product card has .title, .url, .image (.url, .thumbnailUrl,
.alt), .price (as written, such as "$24.00" or "From $18.00"),
.priceAmount (in cents), .priceFrom, .available, .featured,
.description, .vendor and .imageCount.
A product card also has .listed: what the Store chose to show in its lists
on Design, in the Products band. .listed.brand is the brand,
.listed.sizes the sizes that can be bought as one line (such as "Size: S,
M") and .listed.description the description. Each is empty while its switch
is off or the product has none, so a template prints what is there:
{% if product.listed.brand %}.
Functions
| Function | What it gives |
|---|---|
products(collection="mugs", sort="newest", limit=8) |
Products of a list you choose. sort is featured, newest, price_asc, price_desc or title; at most 60. sale=true gives only the products on sale |
brands(limit=12) |
The brands of the Store's products, the one with the most first; each .title, .url (the products narrowed to it) and .count |
testimonials(limit=3) |
Real reviews from buyers to quote: four or five stars, with words, newest first; each .quote, .title, .name, .stars and .product. Only real reviews; a sample Store's are made up for the Design pictures |
bestsellers(limit=5) |
The products sold most in the last year, as product cards with .sold |
price_steps() |
"Under $50" and the like, up to four; each .title, .url and .count |
colours(limit=12) |
The colours products come in (an option called Colour or Color); each .title, .url, .count and .swatch |
catalogue_menu() |
The menu for a large catalogue: .columns (Featured, Categories, Collections, Brands, Price; each .title and .links, each .title, .url, .count), .top (the largest categories, for the bar) and .picture |
collections() |
The Store's Collections, then its categories; each with .kind and .image |
showcase(limit=8, products=4) |
The Collections and categories that have products, with a picture and their first products, for category tiles (each .kind is collection or category, with .title, .url, .image, .count and .products) |
sections() |
The home page's sections from Home page: each has .kind, .title, .text, .button (.label, .url), .image, .video (.url, .type, .mp4Url, .posterUrl), .target (.kind, .title, .url, .description, .image, .product) and .items (a lookbook's pictures with their product cards, or quotes with their names) |
section(item) |
One section, drawn with Magpie's markup: sf-section with sf-section-video, sf-lookbook, sf-story, sf-quotes or sf-spotlight |
money(1250) |
An amount in cents as money: "$12.50" |
text("store.common.sold_out") |
One of the storefront's words, in the language your buyers read. Write your own words instead when you prefer |
Magpie's parts
Interactive parts are drawn by Magpie, so their forms work and stay safe. Place them anywhere in the page they belong to and style them with CSS.
| Part | Where |
|---|---|
head() |
In <head> (required) |
scripts() |
Just before </body> (required) |
search_form() and filters() |
The home and Collection pages |
product_gallery(layout="stage") |
A product's pictures. layout is stage (one large picture and small ones), stacked (all of them down the page) or stacked-pair (two columns) |
product_price() |
The price, which follows the option chosen |
purchase_form() |
Options, quantity and Add to cart (required on the product page) |
back_in_stock(), wishlist_button(), reviews() |
The product page |
recently_viewed() |
The products a buyer looked at last |
cart(), checkout(), gift_card_balance(), plan_checkout() |
Their own pages |
What Magpie refuses
So that a template can never run code or send a buyer's details anywhere, Magpie refuses, with the line:
<script>, attributes such asonclick, andjavascript:addresses;<iframe>,<object>,<embed>,<form>,<base>and<meta http-equiv>;<link>, except for Google Fonts;- in CSS,
url(),@importandimage-set()that load anything but your Store's own files,data:addresses or Google Fonts; - a template larger than 400 KB.
Pictures come from your Store: your logo, cover image and products, or a picture uploaded to your Store and named by its address.
A short template
<!DOCTYPE html>
<html lang="{{ page.language }}">
<head>
{{ head() }}
<style>
.storefront-page { --sf-text: {{ look.colours.text }}; --sf-bg: {{ look.colours.bg }}; font-family: {{ look.fonts.body }}; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }
</style>
</head>
<body>
<header><a href="{{ store.url }}">{{ store.name }}</a> <a href="{{ cart.url }}">Cart ({{ cart.count }})</a></header>
<main id="sf-content">{% content %}</main>
{{ scripts() }}
</body>
</html>
{% macro card(product) %}
<a href="{{ product.url }}">
{% if product.image %}<img src="{{ product.image.thumbnailUrl }}" alt="{{ product.image.alt }}">{% endif %}
<h3>{{ product.title }}</h3>
<p>{{ product.price }}</p>
</a>
{% endmacro %}
{% page "home" %}
<h1>{{ store.name }}</h1>
{{ search_form() }}
<div class="grid">{% for product in products %}{{ _self.card(product) }}{% endfor %}</div>
{% endpage %}
{% page "collection" %}
<h1>{{ collection.title }}</h1>
<div class="grid">{% for product in products %}{{ _self.card(product) }}{% endfor %}</div>
{% endpage %}
{% page "product" %}
{{ product_gallery() }}
<h1>{{ product.title }}</h1>
{{ product_price() }}
{{ purchase_form() }}
{% endpage %}
If Magpie refuses a template and its message does not say why, Contacter l’assistance.
Demander à l’assistance Magpie
Envoyez à l’équipe Magpie une question sur tout ce que cet article n’explique pas.