Skip to content

Instantly share code, notes, and snippets.

@bstonedev
Last active April 23, 2022 11:26
Show Gist options
  • Save bstonedev/27bfd001151143e90fbb0ef343ee0e1b to your computer and use it in GitHub Desktop.
Save bstonedev/27bfd001151143e90fbb0ef343ee0e1b to your computer and use it in GitHub Desktop.
Shopify Liquid Cheatsheet

The Loops

-- product in all-products

{% for product in collections.all-products.products %}
   {{ product.title }}
   <ul>
       <li>{{ variant.image.src }} - Variant Image Object</li>
       <li>{{ variant.price }} - Variant Price</li>
       <li>{{ variant.url }} - Variant URL</li>
       <li>{{ variant.id }} - Variant ID</li>
       <li>{{ variant.sku }} - Variant SKU</li>
       <li>{{ variant.barcode }} - Variant Barcode</li>
       <li>{{ variant.inventory_quantity }} - Variant Quantity</li>
       <li>{{ variant.incoming }} - Variant Incoming Inventory?</li>
       <li>{{ variant.next_incoming_date }} - When is next incoming inventory arriving?</li>
       <li>{{ variant.requires_shipping }} - Does it require shipping?</li>
       <li>{{ variant.requires_shipping }} - Is it currently selected via URL paramter?</li>
       <li>{{ variant.requires_shipping }} - Charging tax in the Variant?</li>
       <li>{{ variant.weight }} - What is Variant weight?</li>
       <li>{{ variant.weight | weight_with_unit }} - What is Variant weight in KG?</li>
       <li>{{ variant.weight_unit }} - What is configured unit?</li>
       <li>{{ variant.inventory_management }} - What inventory tracking service are you using?</li>
   </ul>
{% endfor %}

-- product in all-products --- variant in product

{% for product in collections.all-products.products %}
   {{ product.title }}
   {% for variant in product.variants %}
   {{ variant.title }}
   <ul>
       <li>{{ variant.image.src }} - Variant Image Object</li>
       <li>{{ variant.price }} - Variant Price</li>
       <li>{{ variant.url }} - Variant URL</li>
       <li>{{ variant.id }} - Variant ID</li>
       <li>{{ variant.sku }} - Variant SKU</li>
       <li>{{ variant.barcode }} - Variant Barcode</li>
       <li>{{ variant.inventory_quantity }} - Variant Quantity</li>
       <li>{{ variant.incoming }} - Variant Incoming Inventory?</li>
       <li>{{ variant.next_incoming_date }} - When is next incoming inventory arriving?</li>
       <li>{{ variant.requires_shipping }} - Does it require shipping?</li>
       <li>{{ variant.requires_shipping }} - Is it currently selected via URL paramter?</li>
       <li>{{ variant.requires_shipping }} - Charging tax in the Variant?</li>
       <li>{{ variant.weight }} - What is Variant weight?</li>
       <li>{{ variant.weight | weight_with_unit }} - What is Variant weight in KG?</li>
       <li>{{ variant.weight_unit }} - What is configured unit?</li>
       <li>{{ variant.inventory_management }} - What inventory tracking service are you using?</li>
   </ul>
   {% endfor %}
{% endfor %}

-- product in all-products --- collections in product

{% for product in collections.all-products.products %}
   {{ product.title }}
   <ul>
   {% for collection in product.collections %}
    <li>{{ collection.title }}</li> // Title of Collection that Product belongs to.
    <li>{{ collection.all_products_count }} - All Products Count of Collection that Product belongs to.</li>
    <li>{{ collection.products_count }} - Products Count of Collection that Product belongs to.</li>
    <li>{{ collection.published_at }} - Publish Date of Collection that Product belongs to.</li>
    <li>{{ collection.sort_by }} - Sort By Option of Collection that Product belongs to.</li>
    <li>{{ collection.template_suffix}} - Template Suffix of Collection that Product belongs to.</li>
    <li>{{ collection.current_type }} - Current Product Type of Collection that Product belongs to.</li>
    <li>{{ collection.current_vendor }} - Current Vendor of Collection that Product belongs to.</li>
    <li>{{ collection.description }} - Description of Collection that Product belongs to.</li>
    <li>{{ collection.handle }} - Handle of Collection that Product belongs to.</li>
    <li>{{ collection.id }} - ID of Collection that Product belongs to.</li>
    <li>{{ collection.image }} - Image URL of Collection that Product belongs to.</li>
    <li>{{ collection.next_product.url }} - URL of Next Product of Collection that Product belongs to.</li>
    <li>{{ collection.next_product.title }} - Title of Next Product of Collection that Product belongs to.</li>
    <li>{{ collection.previous_product.url }} -  URL of Previous Product of Collection that Product belongs to.</li>
    <li>{{ collection.previous_product.title }} -  Title of Previous Product of Collection that Product belongs to.</li>
   {% endfor %}
   </ul>
{% endfor %}

-- collection in all_collections

-- collection in all_collections --- product_type in all_types

-- collection in all_collections --- tag in all_tags

-- collection in all_collections --- product_vendor in all_vendors

-- collection in all_collections --- product in collection

-- collection in all_collections --- option in sort_options

-- Item in Cart Loop

{% for item in cart.items %}

{% endfor %}

-- Discount in Item Loop

{% for item in cart.items %}
{% for discount in item.discounts %}

{% endfor %}
{% endfor %}

-- Article in Blog Loop

{% for article in blog.articles %}
    <h2>{{ article.title }}</h2>
{% endfor %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment