Files
jcoffey-dev 89faa7b939
ci / go (pull_request) Successful in 1m32s
ci / editor-ui (pull_request) Successful in 1m33s
Shop: pick a color from a drop-down, and see its photos
A product whose sizes come in colors gets a Color drop-down. Only the
chosen color's sizes show, a size already picked carries over, and the
photos switch to that color's. The script ships with HotDog like the
cart's, only when some page has colors; without it the page lists every
color as before.

The Fourthwall import marks each photo with the color it shows, and
-photos now counts per color.
2026-10-16 17:33:19 -07:00

72 lines
6.2 KiB
HTML

{{ define "main" }}
<link rel="stylesheet" href="{{ asset "packs/shop/shop.css" }}">
{{ $soldOut := eq (printf "%v" .Params.sold_out) "true" }}{{ $cur := .Params.currency }}{{ $base := .Params.price }}
<article class="wrap page product">
{{ with index .Site.Lists .Collection }}<p class="eyebrow"><a href="{{ .Path }}">{{ .Title }}</a></p>{{ end }}
<div class="product-main">
{{/* The big photo, and a small one for each photo under it. Picking a
small one (a click, or the arrow keys) shows it big; no script. */}}
<div class="product-photos">{{ with .Params.photos }}
<div class="photo-stage">
{{ range $i, $p := . }}<div class="photo-slide"{{ with $p.group }} data-group="{{ . }}"{{ end }}>{{ if eq $i 0 }}{{ picture $p.image $p.alt "(min-width: 760px) 55vw, 100vw" "class=product-photo-main fetchpriority=high" }}{{ else }}{{ picture $p.image $p.alt "(min-width: 760px) 55vw, 100vw" "class=product-photo-main loading=lazy" }}{{ end }}</div>{{ end }}
</div>
{{ if gt (len .) 1 }}
<div class="photo-thumbs" role="radiogroup" aria-label="Photos">
{{ range $i, $p := . }}<label class="photo-pick"{{ with $p.group }} data-group="{{ . }}"{{ end }}><input type="radio" name="product-photo"{{ if eq $i 0 }} checked{{ end }}>{{ picture $p.image $p.alt "(min-width: 760px) 9vw, 22vw" "class=product-photo loading=lazy" }}</label>{{ end }}
</div>
{{ end }}
{{ end }}</div>
<div class="product-buy">
<h1>{{ .Title }}</h1>
{{ with .Params.price }}<p class="product-price">{{ if eq (printf "%v" $.Params.price_from) "true" }}<span class="product-from">From</span> {{ end }}{{ money . $cur }}</p>{{ end }}
{{ with .Summary }}<p class="product-summary">{{ . }}</p>{{ end }}
{{ if $soldOut }}
<p class="product-sold-out">Sold out</p>
{{ else if .Params.variants }}
{{ $vs := .Params.variants }}
{{ with .Params.checkout }}
{{/* One form: choose a size or color, and Buy sends it to the checkout. */}}
{{ $field := default "products" .field }}{{ $item := default "{id}" .item }}
<form class="product-form" method="get" action="{{ .action }}" data-cart data-field="{{ $field }}" data-item="{{ $item }}" data-join="{{ default "," .join }}" data-title="{{ $.Title }}" data-href="{{ $.Href }}" data-currency="{{ $cur }}"{{ with $.Params.photos }}{{ with index . 0 }} data-image="{{ pictureAt .image 160 }}"{{ end }}{{ end }}>
{{ range $k, $v := .fields }}<input type="hidden" name="{{ $k }}" value="{{ $v }}">{{ end }}
{{ if eq (len $vs) 1 }}{{ with index $vs 0 }}
<input type="hidden" name="{{ $field }}" value="{{ if .value }}{{ .value }}{{ else }}{{ $item | replace "{id}" (printf "%v" .id) | replace "{qty}" "1" }}{{ end }}" data-cart-variant data-id="{{ default .value .id }}" data-name="{{ with .group }}{{ . }} · {{ end }}{{ .name }}" data-price="{{ .price }}">
{{ with .name }}{{ if ne . "One size" }}<p class="variant-only">{{ with (index $vs 0).group }}{{ . }} · {{ end }}{{ . }}</p>{{ end }}{{ end }}
{{ end }}{{ else }}
{{ if (index $vs 0).group }}{{/* Colors: the picker script turns this on; then only the chosen one's sizes and photos show. */}}{{ variantPicker }}
<label class="variant-group" data-group-pick hidden><span>{{ default "Color" $.Params.choose_group }}</span>
<select data-group-select data-choose="{{ default "Choose one" $.Params.choose }}">{{ $og := "-" }}{{ range $vs }}{{ if ne (default "" .group) $og }}{{ $og = default "" .group }}<option>{{ $og }}</option>{{ end }}{{ end }}</select>
</label>
{{ end }}
{{ $g := "-" }}
{{ range $i, $v := $vs }}{{ $vg := default "" $v.group }}{{ if ne $vg $g }}{{ if ne $i 0 }}</div></fieldset>{{ end }}{{ $g = $vg }}
<fieldset class="variants"{{ if $vg }} data-group="{{ $vg }}"{{ end }}><legend>{{ if $vg }}{{ $vg }}{{ else }}{{ default "Choose one" $.Params.choose }}{{ end }}</legend><div class="variant-list">{{ end }}
{{ $sold := eq (printf "%v" $v.sold_out) "true" }}
<label class="variant{{ if $sold }} variant-sold{{ end }}"><input type="radio" name="{{ $field }}" value="{{ if $v.value }}{{ $v.value }}{{ else }}{{ $item | replace "{id}" (printf "%v" $v.id) | replace "{qty}" "1" }}{{ end }}" required{{ if $sold }} disabled{{ end }} data-option="{{ $v.name }}" data-cart-variant data-id="{{ default $v.value $v.id }}" data-name="{{ with $v.group }}{{ . }} · {{ end }}{{ $v.name }}" data-price="{{ $v.price }}"><span>{{ $v.name }}{{ if $sold }} <small>sold out</small>{{ else if and $v.price (ne (printf "%v" $v.price) (printf "%v" $base)) }} <small>{{ money $v.price $cur }}</small>{{ end }}</span></label>
{{ end }}</div></fieldset>
{{ end }}
<div class="product-buttons">
{{ if cartOn }}<button class="btn primary" type="button" data-cart-add hidden>Add to cart</button>{{ end }}
<button class="btn{{ if not cartOn }} primary{{ end }} product-buy-button" type="submit">{{ default (cond cartOn "Buy now" "Buy") $.Params.button }}</button>
</div>
</form>
{{ else }}
{{/* No checkout form: each size or color is a Buy link of its own. */}}
<div class="product-actions">
{{ range $vs }}{{ if eq (printf "%v" .sold_out) "true" }}<span class="btn variant-sold">{{ with .group }}{{ . }} · {{ end }}{{ .name }} · sold out</span>{{ else }}<a class="btn" href="{{ .buy }}" rel="noopener">{{ with .group }}{{ . }} · {{ end }}{{ .name }}{{ with .price }} · {{ money . $cur }}{{ end }}</a>{{ end }}{{ end }}
</div>
{{ end }}
<p class="product-secure">You'll pay on our payment provider's secure page.</p>
{{ else }}
<div class="product-actions">
{{ with .Params.buy }}<a class="btn primary" href="{{ . }}" rel="noopener">{{ default "Buy" $.Params.button }}</a>{{ end }}
{{ range .Params.options }}<a class="btn" href="{{ .buy }}" rel="noopener">{{ .name }}{{ with .price }} · {{ money . $cur }}{{ end }}</a>{{ end }}
</div>
<p class="product-secure">You'll pay on our payment provider's secure page.</p>
{{ end }}
</div>
</div>
{{ with .Content }}<div class="prose product-details">{{ . }}</div>{{ end }}
</article>
{{ end }}