Skip to content

Instantly share code, notes, and snippets.

SUMBIT YOUR SHOPIFY TIPS TO CONTENT FOR HEADER
Notes:
- Please provide a short (around 40-50 characters) title for your tip that describes what it does. For example:
GOOD: "How to change templates using the view querysting"
BAD: "Want to know how to change templates with a URL?"
- Please choose the most appropriate category for your tip from the provided list
@keirwhitaker
keirwhitaker / srcset.liquid
Created July 12, 2017 14:42
An example of how to use srcset in Shopify themes
{% for product in collection.products %}
<a href="{{ product.url | within: collection }}">
{% assign image = product.featured_image %}
<img src="{{ image.src | img_url: '480x' }}" alt="{{ image.alt | escape }}"
srcset="
{% if image.width > 640 %}{{ image.src | img_url: '640x' }} 640w{% endif %}
{% if image.width > 720 %},{{ image.src | img_url: '720x' }} 720w{% endif %}
{% if image.width > 900 %},{{ image.src | img_url: '900x' }} 900w{% endif %}
"
sizes="(min-width: 960px) 450px, (min-width: 720px) 50vw, 100vw"
@keirwhitaker
keirwhitaker / srcset.liquid
Created July 12, 2017 14:41
An example of how to use srcset in Shopify themes
{% for product in collection.products %}
<a href="{{ product.url | within: collection }}">
{% assign image = product.featured_image %}
<img src="{{ image.src | img_url: '480x' }}" alt="{{ image.alt | escape }}"
srcset="
{% if image.width > 640 %}{{ image.src | img_url: '640x' }} 640w{% endif %}
{% if image.width > 720 %},{{ image.src | img_url: '720x' }} 720w{% endif %}
{% if image.width > 900 %},{{ image.src | img_url: '900x' }} 900w{% endif %}
"
sizes="(min-width: 960px) 450px, (min-width: 720px) 50vw, 100vw"
@keirwhitaker
keirwhitaker / promotions-extract-4.liquid
Created July 11, 2017 09:51
Extract of promotions.liquid #3
"settings": [
{
"id": "title",
"type": "text",
"label": "Title",
"default": "your title here"
},
{
"id": "description",
"type": "textarea",
@keirwhitaker
keirwhitaker / promotions-extract-3.liquid
Created July 11, 2017 09:49
Extract of promotions.liquid #3
"blocks": [
{
"type": "promo-box",
"name": "Promotional Box",
"limit": 1,
"settings": [
{
"id": "title",
"type": "text",
"label": "Title",
@keirwhitaker
keirwhitaker / promotions-extract-2.liquid
Created July 11, 2017 09:48
Extract of promotions.liquid #2
"name": "Promotional Blocks",
"max_blocks": 5,
"presets": [
{
"name": "Promotional Blocks",
"category": "Custom Homepage Content"
}
]
@keirwhitaker
keirwhitaker / promotions-extract-1.liquid
Created July 11, 2017 09:36
Extract of promotions.liquid #1
{% for block in section.blocks %}
{% if block.type == "promo-box" %}
<h3>{{ block.settings.title }}</h3>
<p>{{ block.settings.description }}</p>
{% elsif block.type == "promo-image" %}
<img src="{{ block.settings.promo-image | img_url: '800x' }}" />
{% endif %}
{% endfor %}
@keirwhitaker
keirwhitaker / promotions.liquid
Created July 11, 2017 09:25
A dynamic sections template
{% for block in section.blocks %}
{% if block.type == "promo-box" %}
<h3>{{ block.settings.title }}</h3>
<p>{{ block.settings.description }}</p>
{% elsif block.type == "image-picker" %}
<img src="{{ block.settings.promo-image | img_url: '800x' }}" />
{% endif %}
{% endfor %}
{% schema %}
@keirwhitaker
keirwhitaker / footer-extract-2.liquid
Created July 11, 2017 09:24
Extract of footer.liquid #2
@keirwhitaker
keirwhitaker / footer-extract-1.liquid
Created July 11, 2017 09:22
Extract of footer.liquid #1