Difference between revisions of "Shopify Liquid Examples"

From the Directed Edge Developer Base
Jump to: navigation, search
(Created page with "== Basic Example (Textual output) == This first example demonstrates iterating through different recommendation types (<tt>groups</tt>) and listing a maximum of five recommended ...")
 
Line 1: Line 1:
 
== Basic Example (Textual output) ==
 
== Basic Example (Textual output) ==
This first example demonstrates iterating through different recommendation types (<tt>groups</tt>) and listing a maximum of five recommended products per group:
+
This basic example demonstrates iterating through different recommendation types (called <tt>groups</tt>) and listing a maximum of five recommended products per group:
  
 
<source lang="xml">
 
<source lang="xml">
Line 19: Line 19:
 
{% endfor %}
 
{% endfor %}
 
</source>
 
</source>
 +
 +
In the <tt>{% if group.bundle %}…{% endif %}</tt> block we handle the special case of a group being a bundle. In this case we want to have a different link <tt>{{bundle.buy_link}}</tt> that adds the bundled products to the basket. Also we want to show a message <tt>{{bundle.buy_text}}</tt> that contains the price of the whole bundle. For more information on bundles see the [[Shopify_Liquid|Variable Reference]].

Revision as of 17:52, 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:

{% 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 %}…{% endif %} block we handle the special case of a group being a bundle. In this case we want to have a different link Template:Bundle.buy link that adds the bundled products to the basket. Also we want to show a message Template:Bundle.buy text that contains the price of the whole bundle. For more information on bundles see the Variable Reference.