Difference between revisions of "Shopify Liquid Examples"

From the Directed Edge Developer Base
Jump to: navigation, search
Line 9: Line 9:
 
     <li><a href="{{bundle.buy_link}}">{{bundle.text}}</a></li>
 
     <li><a href="{{bundle.buy_link}}">{{bundle.text}}</a></li>
 
   {% else %}
 
   {% else %}
     {% for product in group.products limit:5%}
+
     {% for product in group.products limit:5 %}
 
     <li>
 
     <li>
 
       <a href="{{product.url}}">{{product.title}}</a>
 
       <a href="{{product.url}}">{{product.title}}</a>

Revision as of 17:57, 10 October 2013

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 in a nested iteration:

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

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