基于2.0 Blocks的可复用自定义产品模板问题求助
自定义Shopify产品模板复用问题:单模板实现产品专属Block内容
我正在创建自定义产品模板,但遇到了复用问题——修改使用该模板的某一产品内容时,所有使用该模板的产品内容都会同步变更,这不符合预期。
当前实现方式(简化版)
Template
{% layout "theme" %} <div class="content--product"> <!-- Product Title --> <div class="product__title"> <h1>{{ product.title }}</h1> </div> <!-- Features (Custom Block) --> {% section 'product-extended-features' %} </div>
Section
{% comment %} Product Features (Custom Block) {% endcomment %} {% schema %} { "name": "Features", "blocks": [ { "type": "Feature", "name": "Item", "settings": [ { "type": "text", "id": "heading", "label": "Content" } ] } ] } {% endschema %} {% comment %} Output component {% endcomment %} {% if section.blocks.size > 0 %} <div class="feed--features"> {% for block in section.blocks %} <div class="item"> <img class="item__image" src="{{ 'icon__check.svg' | asset_url }}" loading="eager"> <p class="item__content">{{ block.settings.heading | escape }}</p> </div> {% endfor %} </div> {% endif %}
问题分析与尝试
我清楚问题根源在于自定义产品数据存储在Section中——Section的配置是全局的,所有使用该模板的产品会共享同一Section内容。
我尝试过用{% render %}标签将产品数据传入snippet,这样能实现产品专属内容,但snippet不支持添加自定义Block所需的schema,无法在Shopify后台可视化配置区块。
补充说明:为何元字段不可行
补充说明[Metafields]
元字段方案无法满足需求:许多区块需要循环(repeater)功能,如果模板中使用多个这类区块,预计需要创建数百个唯一元字段,配置和维护成本极高。
我已经查阅过相关论坛及第三方资料,希望找到一种方法,能在单个模板中为所有产品配置专属的自定义2.0 Blocks内容,求具体实现说明或思路指引。
内容的提问来源于stack exchange,提问作者Graeme Bryson
相关产品推荐
相关产品推荐

