How to skip certain tagged articles in recently-viewed-products?

New Member
4 0 0

So, I'm trying to skip some of our articles in the recently-viewed-products. My tries didn't work out. What am I missing here:

I need the $(handle) in raw so i just captured the value:

 

{% capture currhandle %}{% raw %}${handle}{% endraw %}{% endcapture %}

 

when trying to 

{% if currhandle contains 'nahrung' %} nope{% endif %}

i never get the output, even when i'm sure the currhandle contains "nahrung", which i tested like this:

<!-- {{ currhandle }} -->

 

What am I doing wrong here?

I want to achieve that i add a invisble class to those articles containing "nahrung".

 

Thanks for any help

0 Likes
Highlighted
Shopify Partner
1361 158 245

This snippet should just do it:

{% if handle contains 'nahrung' %} nope{% endif %}

Not sure what you are trying to achieve using {% raw %}. {% raw %} is used to capture the code as liquid so it can then be interpreted. As a result, the if doesn't work as the actual value of the currhandle is ${handle} so the match returns false. When you do <!-- {{ currhandle }} -->, liquid code captured inside currhandle variable is interpreted so you get the actual value.

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
Highlighted
New Member
4 0 0

Thanks for your reply. Our theme is Ella.

The code piece is loaded via xhr, so if I use handle directly, I'll get just the handle of the article of the product page, and not the handle of the ajax loaded content.

I just need to get the handle of the recenet viewed products, which I only get via the $(handle) in raw to get the tags, or simply check if the handle contains a certain string to display extra info from a metafield.

 

Here's the important part of the template:

  {% raw %}
  <script id="recently-viewed-product-grid-template" type="text/x-jquery-tmpl">
  {% endraw %}

  <div class="grid-item col-6 col-md-4 col-lg-3 col5 {% if settings.product_image_border %}grid-item-border{% endif %}">
    <div class="inner product-item{% raw %}{{if !available}} sold-out {{/if}}{{if compare_at_price_min > price_min}} on-sale{{/if}}" data-product-id="product-${id}">
    	<div class="inner-top">
			<div class="product-top">
            	<div class="product-image">
    				<a href="${url}" class="product-grid-image" data-collections-related="/collections/${collection}?view=related">
                      <img src="${featured_image}" alt="${featured_image.alt}"/>
                    </a>
    			</div>
                <div class="product-label">
                  {{if compare_at_price_min > price_min}} 
                    <strong class="label sale-label">
                      <span {% endraw %}{% if settings.enable_multilang %}data-translate="products.product.sale"{% endif %}>
                          {{ 'products.product.sale' | t }}{% raw %}
                      </span>
    				</strong>
                  {{/if}}
                  {{if !available}}
                    <strong class="label sold-out-label">
                      <span {% endraw %}{% if settings.enable_multilang %}data-translate="products.product.sold_out"{% endif %}>
                      	{{ 'products.product.sold_out' | t }}{% raw %}
                      </span>
                    </strong>
                  {{/if}}
                  
                  ${( tagLabel = false ),''}
					{{if tags}}
                      {{each tags}} 
                          {{if $value =="label" || $value =="Label"}}
                              ${( tagLabel = true ),''}
                          {{/if}}
                       {{/each}}
                   {{/if}}
                   
                   {{if tagLabel}}
                    <strong class="label custom-label">
                      <span {% endraw %}{% if settings.enable_multilang %}data-translate="products.product.custom_label"{% endif %}>
                      	{{ 'products.product.custom_label' | t }}{% raw %}
                      </span>
                    </strong>
                  {{/if}}
                 
                </div>
                
                <div class="product-des abs-center">
                    {% endraw %}
                    {% if settings.enable_wishlist %}
                    {% raw %}

                    <a class="wishlist" data-icon-wishlist href="#" data-product-handle="${handle}" data-id="${id}">
                        <i class="fa fa-heart" aria-hidden="true"></i>
                        <span class="wishlist-text text-hover"{% endraw %}{% if settings.enable_multilang %} data-translate="wishlist.general.add_to_wishlist"{% endif %}>
                            {{ 'wishlist.general.add_to_wishlist' | t }}{% raw %}
                        </span>
                    </a>

                    {% endraw %}
                    {% endif %} 
                	{% raw %}
                    
                    {% endraw %}
                    {% if settings.display_button %}
                    {% raw %}
                    <div class="action">
                        <form action="/cart/add" method="post" class="variants" data-id="product-actions-${id}" enctype="multipart/form-data">    
                            {{if !available}}
                                <button class="btn add-to-cart-btn" type="submit" disabled="disabled" {% endraw %}{% if settings.enable_multilang %}data-translate="products.product.unavailable"{% endif %}>
                                    {{ 'products.product.unavailable' | t }}{% raw %}
                                </button>
                            {{else variants.length > 1 }}
                                <a class="btn" href='${url}' title='${title}' {% endraw %}{% if settings.enable_multilang %}data-translate="products.product.select_options"{% endif %}>
                                {{ 'products.product.select_options' | t }}{% raw %}
                                </a>
                            {{else}}
                              <input type="hidden" name="id" value="${variants[0].id}" />      
                              <button data-btn-addToCart class="btn add-to-cart-btn" type="submit" {% endraw %}{% if settings.enable_multilang %}data-translate="products.product.add_to_cart"{% endif %}>
                              {{ 'products.product.add_to_cart' | t }}{% raw %}
                              </button>
                            {{/if}}
                        </form>
                    </div>
                    {% endraw %}
                    {% endif %}
                    {% raw %}
                        				                    
                    {% endraw %}
                    {% if settings.display_product_reviews %}
                    {% raw %}
                    <span class="shopify-product-reviews-badge" data-id="${id}"></span>
                    {% endraw %}
                    {% endif %}
                    {% raw %}
    			</div>
                
                <div class="product-des abs-bottom">
    			{% endraw %}
                {% if settings.enable_quick_view %}
                {% raw %}
                   <a class="quickview-button" href="javascript&colon;void(0)" id="${handle}">
                     <span {% endraw %}{% if settings.enable_multilang %}data-translate="products.product.quick_view"{% endif %}>
                        {{ 'products.product.quick_view' | t }}{% raw %}
    				 </span>                        
    			   </a>
                {% endraw %}
                {% endif %}
                {% raw %}
    			</div>
    		</div>
            
            <div class="product-bottom">
            	{% endraw %}
            	{% if settings.show_vendor %}
                {% raw %}
            	<div class="product-vendor">
                	<a href="/collections/vendors?q=${vendor}" title="Anna">${vendor}</a>                
    			</div>
                {% endraw %}
                {% endif %}	
                {% raw %}
                
                {% endraw %}
                {% if settings.enable_multilang %}
                {% raw %}
                  <a class="product-title lang1" href="${url}">${splitTitle(title)}</a>
                  <a class="product-title lang2" href="${url}">${splitTitle2(title)}</a>
                {% endraw %}
                {% else %}
                {% raw %}
                  <a class="product-title lang1" href="${url}">${splitTitle(title)}</a>
                {% endraw %}
                {% endif %}
                {% raw %}
                
                <div class="price-box">
    				{{if compare_at_price_min > price_min}} 
                      <p class="sale">
                        <span class="old-price">
                        	{{html Shopify.formatMoney(compare_at_price_min, window.money_format)}}
    					</span>
                        
                        <span class="special-price">
                        	{{if price_varies}}
                            {% endraw %}{% include 'varies_from' %}{% raw %}
                        	{{/if}}
                            {{html Shopify.formatMoney(price_min, window.money_format)}}
    					</span>
                      </p>
                    {{else}}
                      <p class="regular-product">
                        <span>
                        	{{if price_varies}}{% endraw %}{% include 'varies_from' %}{% raw %}{{/if}}
                            {{html Shopify.formatMoney(price_min, window.money_format)}}
    					</span>
                      </p>
                    {{/if}}
    			</div>                                
    		</div>                        
      </div>
    </div>
  </div>

</script>
{% endraw %}

 

 

0 Likes