I created an in-line table with 3 boxes. I have also captured an array. My question now is, how can I force a line break inside the boxes whenever the strings in my array are encountered?
Desired output: Notice the 3 boxes and how In , oz, and Count are on a second line.
Desired Output
my code so far:
<a href="{{ filtered_variant.url | default: product.url | within: collection }}" class="product-item__title text--strong link" style="text-align:center;">
<img src="https://cdn.shopify.com/s/files/1/0581/6434/7087/files/stars.png?v=1648243736" >
<div class="sku-line" style="font-family:'Roboto'; "><h2>{{ product.variants[0].sku }}</h2></div>
{% if settings.plus_enable_collection_headings and product.title contains "|" %}
{% assign product_title = product.title | split: "|" %}
<div class="plus-coll-h1 plus-margin heading h1" style="font-weight:100; font-family:'Roboto' font-style:italic;" > {{ product_title[0] }}</div>
<div class="plus-coll-h2 plus-margin heading h2" style="font-weight:300; font-family:'Roboto'"> {{ product_title[1] }}</div>
{% capture word_break_array %}
IN
oz
grams
color
mm
Count
{% endcapture %}
{% assign num = 2 %}
{% if product_title[2] contains "-" %}
{% assign custom_boxes = product_title[2] | split: "-" %}
{% for val in word_break_array %}
{% if custom_boxes contains val %}
{% assign custom_boxes = custom_boxes | newline_to_br | strip_newlines | split: '<br>' %}
<table class="custom-table">
{% tablerow i in (0..num) %}
<div class="collection-detail-boxes"style="font-weight:800;"> {{ custom_boxes[i] }}</div>
{% endtablerow %}
{% endif %}
{% endfor %}
</table>
{% else %}
<div class="plus-coll-h2 plus-margin heading h2" style="font-family:'Roboto';"> {{ product_title[2] }}</div>
{% endif %}
</a>
{% else %}
{{ product.title | remove: "|" }} <span style=""></span>
{% endif %}
Related
i have created custom code sidebar filter. if filter by one tag its working fine, suppose if we click another tag no product details are showing.
Snippet/sidebar-filter.liquid
{% for block in section.blocks %}
{% assign heading = block.settings.filter_heading %}
{% assign tags = block.settings.filter_tags | split: ',' %}
<div class="collection-filter-tag-category">
<h4> {{ heading }} </h4>
<div class="filter-li-scroll">
{% for t in tags %}
{% assign tag = t | strip %}
{% if current_tags contains tag %}
<li class="active">
{{ tag | link_to_remove_tag : tag }}
</li>
{% else %}
<li class="">
{{ tag | link_to_add_tag : tag }}
</li>
{% endif %}
{% endfor %}
</div>
</div>
{% endfor %}
Templates/collection.liquid:
{% section 'collection-template' %}
Templates/collection-template.liquid:
<div id="collection-product-filter-pane">
<div class="sidebar_filter">
{% include 'sidebar-filter' %}
</div>
<div class="page-width" id="Collection">
{% if section.settings.layout == 'grid' %}
{% case section.settings.grid %}
{% when '2' %}
{%- assign grid_item_width = 'medium-up--one-half' -%}
{% when '3' %}
{%- assign grid_item_width = 'small--one-half medium-up--one-third' -%}
{% when '4' %}
{%- assign grid_item_width = 'small--one-half medium-up--one-quarter' -%}
{% when '5' %}
{%- assign grid_item_width = 'small--one-half medium-up--one-fifth' -%}
{% endcase %}
<div class="grid grid--uniform{% if collection.products_count > 0 %} grid--view-items{% endif %}">
{% for product in collection.products %}
<div class="grid__item grid__item--{{section.id}} {{ grid_item_width }}">
{% include 'product-card-grid', max_height: max_height %}
</div>
{% else %}
{% comment %}
Add default products to help with onboarding for collections/all only.
The onboarding styles and products are only loaded if the
store has no products.
{% endcomment %}
{% if collection.handle == 'all' and collection.all_vendors.size == 0 and collection.all_types.size == 0 %}
<div class="grid__item">
<div class="grid grid--uniform">
{% for i in (1..limit) %}
<div class="grid__item {{ grid_item_width }}">
<div class="grid-view-item">
<a href="#" class="grid-view-item__link">
<div class="grid-view-item__image">
{% capture current %}{% cycle 1, 2, 3, 4, 5, 6 %}{% endcapture %}
{{ 'product-' | append: current | placeholder_svg_tag: 'placeholder-svg' }}
</div>
<div class="h4 grid-view-item__title">{{ 'homepage.onboarding.product_title' | t }}</div>
<div class="grid-view-item__meta">
<span class="product-price__price">$19.99</span>
</div>
</a>
</div>
</div>
{% endfor %}
</div>
</div>
{% else %}
{%- assign is_empty_collection = true -%}
{% endif %}
{% endfor %}
</div>
{% else %}
<div class="list-view-items">
{% for product in collection.products %}
<a href="{{ product.url | within: collection }}" class="list-view-item">
{% include 'product-card-list', product: product %}
</a>
{% else %}
{% comment %}
Add default products to help with onboarding for collections/all only.
The onboarding styles and products are only loaded if the
store has no products.
{% endcomment %}
{% if collection.handle == 'all' and collection.all_vendors.size == 0 and collection.all_types.size == 0%}
{% for i in (1..4) %}
<a href="#" class="list-view-item">
<div class="list-view-item__image-column">
<div class="list-view-item__image-wrapper">
<div class="list-view-item__image">
{%- assign placeholder = 'placeholder-product-' | append: i -%}
{% include placeholder %}
</div>
</div>
</div>
<div class="list-view-item__title-column">
<div class="list-view-item__title">{{ 'homepage.onboarding.product_title' | t }}</div>
</div>
<div class="list-view-item__price-column">
<span class="product-price__price">$19.99</span>
</div>
</a>
{% endfor %}
{% else %}
{%- assign is_empty_collection = true -%}
{% endif %}
{% endfor %}
</div>
{% endif %}
{% if is_empty_collection %}
<div class="grid__item small--text-center">
<p class="text-center">{{ 'collections.general.no_matches' | t }}</p>
</div>
{% endif %}
{% if paginate.pages > 1 %}
{% include 'pagination' %}
{% endif %}
</div>
</div>
if filter by another tag no product list coming
please help me to get result, I'm stucking two days pls someone help me
In Snippets/product-form.liquid there's a block of code:
<div class="swatch_options">
{% for option in product.options %}
{% include 'product-swatch' with option %}
{% endfor %}
</div>
This is displaying options for products with X's over the unavailable swatches:
<div data-value="option name" class="swatch-element color optionName-swatch available soldout">
<div class="tooltip">Option Name</div>
<label for="optionName">
<span class="crossed-out"></span>
</label>
</div>
When those non-compatible variants are clicked, a large "UNAVAILABLE" message is displayed:
<p class="modal_price" itemprop="offers" itemscope="" itemtype="http://schema.org/Offer">
<meta itemprop="priceCurrency" content="USD">
<meta itemprop="seller" content="site">
<link itemprop="availability" href="http://schema.org/InStock">
<meta itemprop="itemCondition" content="New">
<span class="sold_out">Unavailable</span>
<span itemprop="price" content="10.00" class="">
<span class="current_price "></span>
</span>
<span class="was_price"></span>
<span class="sale savings"></span>
</p>
I've tried checking for variant.available, product.variants.first.available, and variant.inventory_quantity > 0 before {% include 'product-swatch' with option %}, without success.
How do I hide the non-compatible variants?
Edit: Here's what's currently inside of product-swatch.liquid:
{% comment %}
Set the extension of your color files below. Use 'png', 'jpeg', 'jpg' or 'gif'.
{% endcomment %}
{% assign file_extension = 'png' %}
{% assign swatch = product-swatch %}
{% assign found_option = false %}
{% assign is_color = false %}
{% assign option_index = 0 %}
{% for option in product.options %}
{% if option == swatch %}
{% assign found_option = true %}
{% assign option_index = forloop.index0 %}
{% assign downcased_option = swatch | downcase %}
{% if downcased_option contains 'color' or downcased_option contains 'colour' %}
{% assign is_color = true %}
{% endif %}
{% endif %}
{% endfor %}
<div class="swatch clearfix" data-option-index="{{ option_index }}">
<div class="option_title">{{ swatch }}</div>
{% assign values = '' %}
{% for variant in product.variants %}
{% if variant.available %}
{% assign value = variant.options[option_index] %}
{% unless values contains value %}
{% assign values = values | join: ',' %}
{% assign values = values | append: ',' | append: value %}
{% assign values = values | split: ',' %}
<input id="swatch-{{ option_index }}-{{ value | handle }}-{{ product.id }}" type="radio" name="option-{{ option_index }}" value="{{ value | escape }}"{% if forloop.first %} checked{% endif %} />
<div data-value="{{ value | escape }}" class="swatch-element {% if is_color %}color {% endif %}{{ value | handle }}-swatch {% if variant.available %}available{% else %}soldout{% endif %}">
{% if is_color %}
<div class="tooltip">{{ value }}</div>
{% endif %}
{% if is_color %}
<label for="swatch-{{ option_index }}-{{ value | handle }}-{{ product.id }}" style="background-image: url({{ value | handle | append: '.' | append: file_extension | asset_img_url: '50x' }}); background-color: {{ value | split: ' ' | last | handle }};">
<span class="crossed-out"></span>
</label>
{% else %}
<label for="swatch-{{ option_index }}-{{ value | handle }}-{{ product.id }}">
{{ value }}
<span class="crossed-out"></span>
</label>
{% endif %}
</div>
{% endunless %}
{% endif %}
{% endfor %}
</div>
It seems you're looking for the Linked Options functionality.
Have a look at this doc:
https://help.shopify.com/themes/customization/navigation/link-product-options-in-menus
The code is hosted on GitHub:
https://gist.github.com/carolineschnapp/1083007
It's adjusted to work with swatches as well (I suppose you're using the default implementation).
Edit your product-swatch.liquid file under "snippets" folder.
Find {% for variant in product.variants %} and Put {% if variant.available %} right after it.
Find {% endfor %} and Put {% endif %} right before it.
If its not working, share the codes of product-swatch.liquid with us.
What I'm trying to accomplish is when a user is on an individual blog article/post, I want to display unique "related articles" based off of matching tags.
Here's what I have so far:
{% for tag in article.tags %}
{% assign counter = 0 %}
{% for article in blog.articles %}
{% if article.tags contains tag and counter < 2 %}
{% assign counter = counter | plus: 1 %}
<li class="well">
{% if article.excerpt.size > 0 %}
<div class="thumb-article">
<a href="{{ article.url }}">
{{ article.excerpt }}
</a>
</div>
{% endif %}
<h3>{{ article.title }}</h3>
<p>{{ article.content | strip_html | strip_newlines | truncatewords: 40 }}</p>
</li>
{% endif %}
{% endfor %}
{% endfor %}
Surprisingly, (to me since this is my first experience with Shopify and liquid) it works, just a little too well as it gets duplicate posts.
Is there some way I can keep it from getting duplicate articles?
For those who also searching how to implement related blog posts to a blog not product like in the links provided, there is the fix for code above:
...
{% assign skip_articles = article.handle | split: '.....' %}
...
{% for ...
{% if ...
{% unless skip_articles contains related_article.handle %}
...
{% assign temp = related_article.handle | split: '.....' %}
{% assign skip_articles = skip_articles | concat: temp %}
...
split by anything you wouldn't find in handle to create array
ending up with something like this:
<div class='relatedArticles'>
{% for tag in article.tags %}
{% assign counter = 0 %}
{% assign skip_articles = article.handle | split: '.....' %}
{% for related_article in blog.articles %}
{% if related_article.tags contains tag and counter < 6 %}
{% unless skip_articles contains related_article.handle %}
{% assign counter = counter | plus: 1 %}
{% assign temp = related_article.handle | split: '.....' %}
{% assign skip_articles = skip_articles | concat: temp %}
<div class="well">
<h3>{{ related_article.title }}</h3>
{% if related_article.excerpt.size > 0 %}
<p>{{ related_article.excerpt }}</p>
{% else %}
<p>{{ related_article.content | truncatewords: 40 }}</p>
{% endif %}
</div>
{% endunless %}
{% endif %}
{% endfor %}
{% endfor %}
</div>
This thread has what you need: Shopify liquid get related blog posts
It creates an empty related posts variable then defines it in a loop that looks through other posts of that same category. To repeat its answer:
{% assign related_posts = "" %}
{% for article in blogs.blog.articles %}
{% if article.tags contains product.handle %}
{% capture post %}
<li><p>{{ article.title }}</p></li>
{% endcapture %}
{% assign related_posts = related_posts | append:post %}
{% endif %}
{% endfor %}
{% if related_posts.size > 0 %}
<ul> {{ related_posts }} </ul>
{% else %}
No related posts!
{% endif %}
Go to that link above to see the full response.
I was trying to display all the product types of my site in one page , 2 days back it was listing all the all the product type.
But now when that page is loads its giving error like "shopify Liquid error: Memory limits exceeded"
Here is my code
<div class="rte">
{{ page.content }}
<ul class="vendor-list block-grid three-up mobile one-up">
{% for product_type in shop.types %}
{% assign its_a_match = false %}
{% capture my_collection_handle %} {{ type | handleize | strip | escape }} {% endcapture %}
{% assign my_collection_handle_stripped = my_collection_handle | strip | escape %}
{% for collection in collections %}
{% if my_collection_handle_stripped == collection.handle %}
{% assign its_a_match = true %}
{% endif %}
{% endfor %}
{% if its_a_match %}
<li class="vendor-list-item">{{ product_type }}</li>
{% endif %}
{% endfor %}
</ul>
</div>
how can i overcome this problem ?
Try the following. It's faster and more efficient.
<div class="rte">
{{ page.content }}
<ul class="vendor-list block-grid three-up mobile one-up">
{% for product_type in shop.types %}
{% assign type = product_type | strip | escape | handleize %}
{% assign collection = collections[type] %}
{% if collection.handle != '' %}
<li class="vendor-list-item">{{ product_type }}</li>
{% endif %}
{% endfor %}
</ul>
</div>
I want to update the "New Order Notification" mail for my Shopify store with custom HTML code, but while pasting the code it simply doesn't paste 100% of it. I've contacted Shopify and they've told me there is no character limit but a file size limit of 64 or 128 kb.
The store has 18 main categories (collections). What I'm trying to do is make sure the products get sorted based on category name.
The following piece of code appears 18 times (for every category) in the custom template:
{% if verse_kantenklaar_maaltijden_salades != blank %}
<tr>
<td colspan="2">
<h2 style="margin-bottom:15px;margin-top:5px!important;font-weight:bold;">Verse kant-en-klaar maaltijden - salades</h2>
</td>
</tr>
{% for line_item_id in verse_kantenklaar_maaltijden_salades %}
{% for line_item in line_items %}
{% capture line_item_string %}{{line_item.id}}{% endcapture %}
{% if line_item_id == line_item_string %}
{% assign bonus = 'no' %}
{% for tag in line_item.product.tags %}
{% if tag == 'Bonus' %}
{% assign bonus = 'yes' %}
{% endif %}
{% endfor %}
<tr>
<td>
<img alt="" src="{{ line_item.product.featured_image | product_img_url: 'large' }}" style="width: 400px;">
</td>
<td style="text-align:left;">{{ line_item.title }} ({{ line_item.product.metafields.global.item_size }})<br>
<span style="font-size:34px;font-weight:bold;">
{% if bonus == 'yes' %}
{{ line_item.product.metafields.global.wpob | round: 2 }}
{% else %}
{{ line_item.product.metafields.global.wpo | round: 2 }}
{% endif %}
</span>
{% if bonus == 'yes' %}
<span style="font-size:18px;font-weight:bold;">BONUS</span>
{% endif %}
{% if line_item.quantity > 1 %}<span class="item_count" style="display: block;position: relative;width: 50px;text-align: center;background-color: #d14836;color: white;font-weight: 700;min-width: 80px;line-height: 40px;border-radius: 50px;">{{ line_item.quantity }}</span>{% endif %}
</td>
</tr>
{%endif%}
{% endfor %}
{% endfor %}
{% endif %}
For the full code (with 3 categories) take a look at this gist.
Is there a way to simplify (using loops) or compress this to make sure the total template stays within Shopify limits?
Or might this be caused by something else? The total code length is around 1500 lines.
For anyone interested, here's the more efficient version (thanks to Evulse):
{% assign sort_array = "" %}
{% for line_item in cart.items %}
{% for tag in line_item.product.tags %}
{% if tag == 'Tag I want second' %}
{% assign sort_array = sort_array | append: 'B:' | append: line_item.id | append: ',' %}
{% endif %}
{% if tag == 'Tag I want First' %}
{% assign sort_array = sort_array | append: 'A:' | append: line_item.id | append: ',' %}
{% endif %}
{% if tag == 'Tag I want Third' %}
{% assign sort_array = sort_array | append: 'C:' | append: line_item.id | append: ',' %}
{% endif %}
{% endfor %}
{% endfor %}
{% assign sort_array = sort_array | split: ',' | sort %}
{% for prefixed_line_item_id in sort_array %}
{% for line_item in cart.items %}
{% capture line_item_string %}{{line_item.id}}{% endcapture %}
{% assign line_item_id = prefixed_line_item_id | split: ':' | last %}
{% if line_item_id == line_item_string %}
{{line_item.product.title}}
{%endif%}
{% endfor %}
{% endfor %}