shopify - How do I shorten this liquid code? -


i want update "new order notification" mail shopify store custom html code, while pasting code doesn't paste 100% of it. i've contacted shopify , they've told me there no character limit file size limit of 64 or 128 kb.

the store has 18 main categories (collections). i'm trying make sure products sorted based on category name.

the following piece of code appears 18 times (for every category) in 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>    {% line_item_id in verse_kantenklaar_maaltijden_salades %}       {% line_item in line_items %}           {% capture line_item_string %}{{line_item.id}}{% endcapture %}           {% if line_item_id == line_item_string %}              {% assign bonus = 'no' %}              {% tag in line_item.product.tags %}               {% if tag == 'bonus' %}                 {% assign bonus = 'yes' %}               {% endif %}             {% endfor %}              <tr>               <td>                 <a href="{{ line_item.product.featured_image | product_img_url: 'master' }}"><img alt="" src="{{ line_item.product.featured_image | product_img_url: 'large' }}" style="width: 400px;"></a>               </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 full code (with 3 categories) take @ this gist.

is there way simplify (using loops) or compress make sure total template stays within shopify limits?

or might caused else? total code length around 1500 lines.

for interested, here's more efficient version (thanks evulse):

{% assign sort_array = "" %}  {% line_item in cart.items %}     {% tag in line_item.product.tags %}          {% if tag == 'tag want second' %}             {% assign sort_array = sort_array | append: 'b:' | append: line_item.id | append: ',' %}         {% endif %}         {% if tag == 'tag want first' %}             {% assign sort_array = sort_array | append: 'a:' | append: line_item.id | append: ',' %}         {% endif %}           {% if tag == 'tag want third' %}             {% assign sort_array = sort_array | append: 'c:' | append: line_item.id | append: ',' %}         {% endif %}      {% endfor %} {% endfor %}  {% assign sort_array = sort_array | split: ',' | sort %}  {% prefixed_line_item_id in sort_array %}     {% 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 %} 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -