Changing liquid to read from multiple templates
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 11.9k
- Forks
- 1.5k
- Avg merge
- 17h 55m
- Merged PRs (30d)
- 3
Description
We have the code working fr 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 :)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Compare the existing show10 logic with the already-created product.show20.liquid and product.show50.liquid templates. No repository source file, test, or entry point is identified; done would mean the templates handle the requested names and display the intended inventory values.
Written by the indexing model from the issue text.
Assessment
- Domain
- web-dev
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100