Shopify Liquid Examples

From the Directed Edge Developer Base
Revision as of 17:52, 10 October 2013 by Lucijan (talk | contribs)
Jump to: navigation, search

Basic Example (Textual output)

This basic example demonstrates iterating through different recommendation types (called groups) and listing a maximum of five recommended products per group:

{% for group in groups %}
  {% if group.bundle %}
  <li><a href="{{bundle.buy_link}}">{{bundle.text}}</a></li>
  {% else %}
  {% for product in group.products limit:5%}
    <a href="{{product.url}}">{{product.title}}</a>
    for {{product.price | money}}
  {% endfor %}
  {% endif %}
{% endfor %}

In the {% if group.bundle %}…{% endif %} block we handle the special case of a group being a bundle. In this case we want to have a different link link that adds the bundled products to the basket. Also we want to show a message text that contains the price of the whole bundle. For more information on bundles see the Variable Reference.