Files
season/snippets/hero-product.liquid
T
2026-10-02 19:32:54 -06:00

71 lines
2.1 KiB
Plaintext

{% doc %}
Renders a featured product card for the homepage hero.
@param {product} product - Product to show in the card
@example
{% render 'hero-product', product: block.settings.product %}
{% enddoc %}
{% liquid
assign variant = product.selected_or_first_available_variant
assign card_image = product.featured_image
assign hover_image = blank
assign image_alt = card_image.alt | default: product.title
for image in product.images offset: 1 limit: 1
assign hover_image = image
endfor
%}
<article class="hero__card">
<a class="hero__card-media" href="{{ product.url }}">
{% if card_image %}
{{
card_image
| image_url: width: 200
| image_tag:
alt: image_alt,
widths: '100, 140, 200',
sizes: '(max-width: 1023px) 70px, 100px',
class: 'hero__card-image',
loading: 'eager'
}}
{% if hover_image != blank %}
{{
hover_image
| image_url: width: 200
| image_tag:
alt: '',
widths: '100, 140, 200',
sizes: '(max-width: 1023px) 70px, 100px',
class: 'hero__card-image hero__card-image--hover',
loading: 'lazy'
}}
{% endif %}
{% endif %}
</a>
<div class="hero__card-copy">
<a class="hero__card-title" href="{{ product.url }}">{{ product.title | escape }}</a>
<p class="hero__card-price">{{ variant.price | money_without_trailing_zeros }}</p>
</div>
{% form 'product', product, class: 'hero__form' %}
<input type="hidden" name="id" value="{{ variant.id }}">
<input type="hidden" name="quantity" value="1">
<button
class="hero__cart"
type="submit"
{% unless variant.available %}
disabled
{% endunless %}
aria-label="{% if variant.available %}{{ 'hero.add_to_cart' | t: product: product.title }}{% else %}{{ 'hero.sold_out' | t }}{% endif %}"
>
<span class="hero__cart-icon" aria-hidden="true">
{{ 'icon-bag.svg' | inline_asset_content }}
</span>
</button>
{% endform %}
</article>