D
D
daff0022020-07-26 12:11:40
Twig
daff002, 2020-07-26 12:11:40

How to make a condition in twig less than or equal?

Good afternoon, tell me how to make a condition in twig
In the template, we have the output of product categories in which it is located (some have more than 1, and some have 1), I need products with 1 or less category not to display this cat_list block

{% if cat_list %}
               <div class="uni-module product-cat_list">
        <div class="category-list row row-flex">
                   {% for cat in cat_list %}
                   <div>
              <a href="{{ cat.href }}" class="category-list__item image-after">
                {% if cat.image_src %}
                  <img src="{{ cat.image_src }}" alt="{{ cat.name }}" title="{{ cat.name }}" class="category-list__img img-responsive" />
                {% endif %}
                {{ cat.name }}
            </a>
           </div>
                   {% endfor %}				   
           </div>
        </div>
        <script>
          $('.product-cat_list').uniModules({
            type:'{{type_view is defined ? type_view : 'carousel'}}',
            loop: {{cat_list|length > 4 ? 'true' : 'false'}}
          });
        </script>
            {% endif %}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2020-07-26
@daff002

Instead {% if cat_list %}use:
{% if cat_list and cat_list|length > 1 %}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question