0

我可以根据产品所属的类别在Product.html页面上创建 if 语句吗?像这样的东西:

{% if product.category.name == 'Shirts' %}
     <div>Some Content</div>
{% endif %}

谢谢。

4

1 回答 1

0

由于产品可以列在多个类别中,因此您需要使用for循环遍历所有类别,然后包含一条if语句来检查名称 - 如下所示:

{% for category in product.categories %}
  {% if category.name == 'Shirts' %}
    <div>Your content</div>
  {% endif %}
{% endfor %}
于 2015-12-14T23:35:09.833 回答