我正在进行我的第一个 JinJa2 项目。我想展示汽车。一辆车可以有一个或多个选项。如果一辆车有一个选择,请展示出来。如果有更多,暂时隐藏它。这是我的代码:
//...
{% set products = ['Audi', 'BMW', 'Mercedes', 'Porsche'] %}
{% set options = ['Small', 'Sport', 'Coupe', 'Jeep'] %}
{% for product in products %}
{% include '../car-product-item.html' with context %}
{% endfor %}
{% if options|length > 1 %}
//If a car has more options, hide this options for the moment
<div class="order-more-options" style="display: none; background: green">
{% for product in options %}
{% include '../car-product-item.html' with context %}
{% endfor %}
</div>
{% elif options|length == 1 %}
//If a car has one option, show this option
<div class="order-more-options" style="display: block; background: orange">
{% for product in options %}
{% include '../car-product-item.html' with context %}
{% endfor %}
</div>
{% endif %}
//...
由于某种原因,它不起作用。选项总是隐藏的。我究竟做错了什么?
我检查了Tutorial,Docu和另一个SO-Question但没有任何帮助。