【发布时间】:2015-03-20 19:14:03
【问题描述】:
我想使用自定义 HTML 代码更新我的 Shopify 商店的“新订单通知”邮件,但在粘贴代码时它根本没有粘贴 100% 的内容。我联系了 Shopify,他们告诉我没有字符限制,但文件大小限制为 64 或 128 kb。
商店有 18 个主要类别(系列)。我正在尝试做的是确保产品根据类别名称进行排序。
以下代码在自定义模板中出现 18 次(针对每个类别):
{% 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>
<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 %}
如需完整代码(包含 3 个类别),请查看 this gist。
有没有办法简化(使用循环)或压缩它以确保整个模板保持在 Shopify 限制范围内?
或者这可能是由其他原因引起的?总代码长度约为 1500 行。
【问题讨论】:
-
这是代码审查,因此与本网站无关。
-
如果您修剪前导空格,您发布的要点将从 ~5kb 变为 ~4kb。如果您将其复制了 18 次,则节省了 18k。
-
@Jubobs 1. 在其他主题上不会使其脱离主题。 2. 对我来说,这听起来很糟糕,而且损坏的代码在 CR 上是特别离题的。
-
@RubberDuck 我根本不建议迁移到 CR。但是,问题的措辞(“有没有办法简化 [...]”)肯定表明这是一个代码审查问题,因此不适合 SO。但做你认为最好的。
-
@Jubobs 就这样,我认为这两个网站都不适合。