Loop is working outside html but not inside html

larsverp
New Member
4 0 0

I build a way to customize the recommended products for a client of mine using tags. Except something weird is going on. The loop I wrote works perfectly fine outside the div, but doesn't do anything inside the div.  What is stopping this code from working on the place it's suppose to go? This is my code:

 

 

 

{% comment %} Variables {% endcomment %}
{% assign similar_products_heading = section.settings.product-similar-products-heading %}
{% assign show_section = section.settings.product-similar-products-show %}
{% assign max_products = 2 %}
{% assign all_the_products = collections.all-products-develop-collection.products %}
{% assign tags = product.tags %}

<--------- OVER HERE IT WORKS LIKE A CHARM

{% if show_section %}
{% unless tags contains 'not-recommend' %}
  <div
    class="product-recommendations--root"
    data-product-id="{{ product.id }}"
    data-empty="false"
    data-max-products="{{ max_products }}"
    data-js-class="ProductRecommendations"
  >
    
    <article class="product-page--container tmp-0-custom" itemscope="" itemtype="https://schema.org/Product">
    <div class="product-page--main-content">
      <div></div>
      <div></div>
      <div>
    {% if recommendations.products_count > 0 %}
      {% if similar_products_heading != blank %}
        <div class="product-recommendations--header">
          <h2 class="product-recommendations--title" data-item="section-heading">
            {{ similar_products_heading }}
          </h2>
        </div>
      {% endif %}      
      
      <div class="product-recommendations--body">
        <div class="product-recommendations--body--container">
          {% for tag in tags %}                            <------------------ OVER HERE IT'S NOT WORKING :(
          	{% for single_product in all_the_products %}
          		{% if tag == single_product.handle %}
          			<div class="product-recommendations--item">
            		{%
            		render 'framework--product--item',
                    product: single_product,
                    view: 'grid'
                    %}	
          			</div>
          		{% endif %}
          	{% endfor %}
          {% endfor %}
        </div>
       </div>
        
	{% endif %}
</div>
</div>
</article>
{% endunless %}
{% endif %}

 

 

Is there something I'm doing wrong?

 

0 Likes
achieveapplabs
Shopify Partner
470 36 74

Look at where you endunless tag ends. You may want to move that up to close off the condition.

Install Approovly to create and track order approvals | We want to hear from you hello@achieveapplabs.com | Follow us on Twitter @achieveapplabs | Custom Shopify Apps achieveapplabs.com
0 Likes
larsverp
New Member
4 0 0

That unless tag is checking if there is no "not-recommend" tag inside the product. Because in that case the product should not even have the recommended products. This tag is not the problem, a script tag is working right under the unless tag.

0 Likes