714 votes
0 answers
shopify - Changing liquid to read from multiple templates
We have the code working for one template (show10) and now we are wanting to add in more template names such as show20, show50 but not sure how to add to the code to get it to read past show10 if the template name is 'show20' or 'show50'. See below what we have working for 'show10':
<div id="shappify-qty-msg"></div>
<div class="order_box">
{% for variant in product.variants %}
{% assign quantity = variant.inventory_quantity %}
{% if variant.metafields.shappify_qb.qb_hide == "1" %}{% else %}
{% if variant.available %}
<div class="variant_row">
<div class="variant_title">{{ variant.title }} ({% if templatename == 'show10' %}{% if quantity > 10 %}10{% else %}{{ variant.inventory_quantity }}{% endif %}{% else %}{{ variant.inventory_quantity }}{% endif %} in Stock)</div>
<div class="variant_input"><input onfocus="this.select()" class="quantity field" data-id="{{ variant.id }}" min="0" {% if templatename == 'show10' %}max="{% if quantity > 10 %}10{% else %}{{ variant.inventory_quantity }}{% endif %}"{% else %}{% unless item.variant.inventory_management == blank or item.variant.inventory_policy == 'continue' %}{% assign max = variant.inventory_quantity %}{% for item in cart.items %}{% if item.id == variant.id %}{% assign max = max | minus: item.quantity %}{% endif %}{% endfor %} max="{{ max }}" {% endunless %}{% endif %} type="text" value="0" tabindex="1" /></div>
</div>
{% else %}
<div class="variant_row">
<div class="variant_title">{{ variant.title }} ({% if templatename == 'show10' %}{% if quantity > 10 %}10{% else %}{{ quantity }}{% endif %}{% else %}{{ variant.inventory_quantity }}{% endif %} in Stock)</div>
<div class="variant_input"><input class="quantity field disabled" type="text" value="0" /></div>
</div>
{% endif %}
{% endif %}
{% endfor %}
{% if product.available %}
<input class="action-button submit button btn center add-to-cart-order-form" type="button" value="Add to cart" />
{% else %}
<input class="disabled" type="button" value="Sold Out" />
{% endif %}
</div>
product.show20.liquid and product.show50.liquid templates have already been made
Grateful for any help on this :)
Undefined asked
Source
Didn't find the answer?
Our community is visited by hundreds of Shopify development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.