如何按类别订购产品?

时间:2015-05-26 14:47:04

标签: bigcartel

在我的产品页面上,我想显示按类别订购的产品。我试过这样的循环,但有一个错误未知的类别标签。任何线索?

 {% for category in categories.active %}
<h2>{{ category.name }}</h2>
    {% for product in category.products %}
      {% if forloop.first %}
        <ul id="products" class="{% if forloop.length == 1 %}single_product{% endif %}{% if forloop.length == 2 %}double_product{% endif %}">
      {% endif %}
      <li id="product_{{ product.id }}" class="product">
        <a href="{{ product.url }}" title="View {{ product.name | escape }}">
          <div class="product_header">
            <h2>{{ product.name }}</h2>
            <span class="dash"></span>            
            <!--<h3>{{ product.default_price | money_with_sign }}</h3>-->
            {% case product.status %}
            {% when 'active' %}
              {% if product.on_sale %}<h5>On Sale</h5>{% endif %}
            {% when 'sold-out' %}
                <h5>Sold Out</h5>
            {% when 'coming-soon' %}
                <h5>Coming Soon</h5>
            {% endcase %}
          </div>
          <div class="product_thumb">
            <img src="{{ product.image | product_image_url | constrain: '560' }}" class="fade_in" alt="Image of {{ product.name | escape }}">
          </div>
        </a>
      </li>
      {% if forloop.last %}
        </ul>
      {% endif %}
    {% endfor %}
{% endfor %}

1 个答案:

答案 0 :(得分:0)

好的,只是设法做我想要的。是在正确的道路上,但有些东西搞乱了。我把它复制在这里。

{% for category in categories.active %}
<h2>{{ category.name }}</h2>
{% for product in category.products %}
{% if forloop.first %}
        <ul id="products">
{% endif %}
<li id="product_{{ product.id }}" class="product">
        <a href="{{ product.url }}" title="View {{ product.name | escape }}">
          <div class="product_header">
            <h2>{{ product.name }}</h2>
            <span class="dash"></span>            
            <!--<h3>{{ product.default_price | money_with_sign }}</h3>-->
            {% case product.status %}
            {% when 'active' %}
              {% if product.on_sale %}<h5>On Sale</h5>{% endif %}
            {% when 'sold-out' %}
                <h5>Sold Out</h5>
            {% when 'coming-soon' %}
                <h5>Coming Soon</h5>
            {% endcase %}
          </div>
          <div class="product_thumb">
            <img src="{{ product.image | product_image_url | constrain: '560' }}" class="fade_in" alt="Image of {{ product.name | escape }}">
          </div>
        </a>
      </li>
      {% if forloop.last %}
        </ul>
      {% endif %}
    {% endfor %}                
{% endfor %}
相关问题