Is it possible to get a list of categories that a product is tied to?

rgismergisme Member Posts: 17

I don't see this available anywhere in the rain variables list. Is this not possible?

5 comments

  • rgismergisme Member Posts: 17

     {% for category in product.categories %}

         <div> {{ category.title }} </div>

     {% endfor %}


    This works.

  • GeannyGeanny Moderator, Lightspeed Staff Posts: 113 moderator

    Thanks, @rgisme ,

    Let us know if you have any additional questions.

    Geanny

  • sspindsspind Member Posts: 13
    edited April 2021

    Ok can you pls tell me why this is not working in collection rain.


    {% for category in shop.categories %}

        {%if category.id == '9775609' %} {% include 'snippets/kategorietop.rain' %}    {% endif %}

     {% endfor %}


    I also tried

    {% for category in product.categories %}

    does not show eather anything

    It should show a snippet selected by a special product category.

  • larry_nalzarolarry_nalzaro Member Posts: 32

    The reason it didn't work, @sspind , is because 9775609 might not be on the first level of the category tree; it might be on the second or third level.

    You should loop on each level so 9775609 will be found. Do it like this:

    {% for category in shop.categories %}
       {% if category.id == '9775609' %} 
          {% include 'snippets/kategorietop.rain' %}
       {% else %}
          {# --- drill to the 2nd level -- #}
          {% if category.subs %}
          {% for category in category.subs %}
             {% if category.id == '9775609' %} 
                {% include 'snippets/kategorietop.rain' %}
             {% else %}
                {% if category.subs %}
                {# --- drill to the 3rd level -- #}
                {% for category in category.subs %}
                   {% if category.id == '9775609' %} 
                      {% include 'snippets/kategorietop.rain' %}
                   {% endif %}
                {% endfor %}      
                {% endif %}         
             {% endif %}
          {% endfor %}      
          {% endif %}
       {% endif %}
    {% endfor %}
    
  • whitelabelwhitelabel Member Posts: 15
     <div class="row">
        <div class="col-12 tags">
            <ul class="d-flex flex-wrap">                       
              {% for category in product.categories %}
                <li><a href="{{ category.url | url }}">{{ category.title }} </li>
              {% endfor %}
            </ul>
        </div>
    </div>
    

    Wij verkopen alle soorten witgoed en inbouw apparaten. Wij bezorgen uw gewenste witgoed gratis aan huis. Ook voor het aansluiten of inbouwen van uw witgoed apparatuur bent u bij ons aan het juiste adres!

    https://www.paulissenwitgoed.shop

Sign In or Register to comment.