The language
Lists & conditions
Two pieces of logic cover nearly every storefront: repeat a template for each item, and show a part only when it applies.
Repeating with .map()
Call .map() on any list from your store and return the widgets for one item. The template is written once and drawn for every item, so styling it styles them all.
<GridView className="grid-cols-2 md:grid-cols-4 gap-4">
{products({ category: "running-shoes", sort: "newest", limit: 8 }).map((item) => (
<Link href={item.url}>
<Column className="gap-2">
<AspectRatio className="aspect-square">
<Image src={item.image} className="w-full h-full object-cover" />
</AspectRatio>
<Text className="text-sm truncate">{item.name}</Text>
<Text className="text-sm font-semibold">{item.price}</Text>
</Column>
</Link>
))}
</GridView>- Use an arrow function:
(item) => …, or(item, index) => …when you need the position. - The body must be JSX: a widget, or parentheses around one.
- The name is yours.
itemis the convention and what the builder writes, but(shoe) => …works too. - Only data can be mapped: store lists (
products({ … }),category("…").children,product.images), not literal arrays.
ErrorOnly data can be mapped, e.g. {products({ limit: 8 }).map(…)} or {product.images.map(…)}
Lists nest, and any list field of an item can be mapped too:
<Wrap className="gap-2">
{category("shoes").children.map((item) => (
<Chip label={item.name} />
))}
</Wrap>Showing when true: &&
{cond && <X/>} draws X only when cond is true. Put ! in front to invert it.
<Column className="gap-2">
{product.onSale && <Chip label="Sale" />}
{product.inStock ? (
<Text className="text-green-700">In stock</Text>
) : (
<Text className="text-red-700">Sold out</Text>
)}
{!product.hasOptions && (
<FilledButton label="Add to cart" onPressed={{ type: "addToCart", product: product.id, variant: product.variantId }} />
)}
</Column>Choosing: ? :
{cond ? <X/> : <Y/>} draws one or the other. Above, the stock line is green or red depending on product.inStock. To change only an element's classes rather than swap it, use backticks.
Hiding empty sections
A list used as a condition is true when it has items. Wrap a section's content in its own list to hide the whole thing, heading included, when a store has nothing to show. The catalog sections the builder adds all do this.
<Container className="py-12 px-6">
{collections({ limit: 3 }) && (
<Column className="gap-6">
<Text semanticsTag="h2">Collections</Text>
<Row className="gap-4">
{collections({ limit: 3 }).map((item) => (
<Text>{item.name}</Text>
))}
</Row>
</Column>
)}
</Container>What conditions can test
A condition is a single data value: a true/false field like onSale, inStock or hasOptions, a value that may be missing like item.image, or a list. Comparisons and arithmetic aren't part of the language. The data provides ready-made flags instead, so templates stay simple to read and safe to edit in the canvas.
ErrorConditions may only test data, e.g. {product.inStock && …} or {!cart.items && …}
In the Layers panel, a .map() shows as a For layer and a condition as an If layer, so the same logic is visible and editable without code. More in the widget reference.