Shopify 从节外部访问节块字段
我正在尝试从节文件模板外部访问节字段中上载的图像的url。是否有一种方法可以访问该部分,获取该部分的块,然后获取单个块的块值?我希望我可以访问调用该部分的页面模板上的促销图像,但在页面模板的另一部分,我希望显示从块上传的图像Shopify 从节外部访问节块字段,shopify,Shopify,我正在尝试从节文件模板外部访问节字段中上载的图像的url。是否有一种方法可以访问该部分,获取该部分的块,然后获取单个块的块值?我希望我可以访问调用该部分的页面模板上的促销图像,但在页面模板的另一部分,我希望显示从块上传的图像 <div id="carouselExampleControls" class="promotions carousel slide" data-ride="carousel"> <div class="carousel-inner">
<div id="carouselExampleControls" class="promotions carousel slide" data-ride="carousel">
<div class="carousel-inner">
{% for block in section.blocks %}
{% if forloop.index == 1 %}
<div class="carousel-item active">
<div class="row m-0 py-3 justify-content-center">
<h6 class="mb-0 row m-0 align-items-center text-uppercase">{{block.settings.promotion-message}} </h6>
<a class="ml-3 btn btn-primary btn-sm" href="{{collections[block.settings.promotion-collection].url}}">{{block.settings.promotion-link-text}}</a>
</div>
</div>
{% else %}
<div class="carousel-item">
<div class="row m-0 py-3 justify-content-center">
<h6 class="mb-0 row m-0 align-items-center text-uppercase">{{block.settings.promotion-message}} </h6>
<a class="ml-3 btn btn-primary btn-sm" href="{{collections[block.settings.promotion-collection].url}}">{{block.settings.promotion-link-text}}</a>
</div>
</div>
{% endif %}
{% endfor %}
</div>
<a class="carousel-control-prev text-dark" href="#carouselExampleControls" role="button" data-slide="prev">
<i class="fas fa-angle-left text-dark"></i>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next text-dark" href="#carouselExampleControls" role="button" data-slide="next">
<i class="fas fa-angle-right text-dark"></i>
<span class="sr-only">Next</span>
</a>
</div>
{% schema %}
{
"name": "Promotions",
"max_blocks": 4,
"settings":[],
"presets": [
{
"name": "Promotions",
"category": "Promotions",
"blocks": [
{
"type": "select"
},
{
"type": "select"
}
]
}
],
"blocks": [
{
"type": "select",
"name": "Promotion",
"settings": [
{
"type": "richtext",
"id": "promotion-message",
"label": "Promotion Message",
"default": "<p>Your promotion message</p>"
},
{
"id":"promotion-link-text",
"type": "text",
"label": "Promotion Link Text",
"default":"Learn More"
},
{
"type": "collection",
"id": "promotion-collection",
"label": "Promotion Collection"
},
{
"id":"promotion-image",
"type": "image_picker",
"label": "Promotion Image"
}
]
}
]
}
{% endschema %}
{% stylesheet %}
{% endstylesheet %}
{% javascript %}
{% endjavascript %}
{section.blocks%中的块的%s}
{%if-forloop.index==1%}
{{block.settings.promotion message}
{%else%}
{{block.settings.promotion message}
{%endif%}
{%endfor%}
{%schema%}
{
“名称”:“促销”,
“最大积木”:4,
“设置”:[],
“预设”:[
{
“名称”:“促销”,
“类别”:“促销”,
“区块”:[
{
“类型”:“选择”
},
{
“类型”:“选择”
}
]
}
],
“区块”:[
{
“类型”:“选择”,
“名称”:“促销”,
“设置”:[
{
“类型”:“richtext”,
“id”:“促销信息”,
“标签”:“促销信息”,
“默认值”:“您的促销信息”
},
{
“id”:“促销链接文本”,
“类型”:“文本”,
“标签”:“促销链接文本”,
“默认值”:“了解更多信息”
},
{
“类型”:“集合”,
“id”:“促销系列”,
“标签”:“促销系列”
},
{
“id”:“促销形象”,
“类型”:“图像选择器”,
“标签”:“促销形象”
}
]
}
]
}
{%endschema%}
{%stylesheet%}
{%endstylesheet%}
{%javascript%}
{%endjavascript%}
您不能传递或访问本节以外的任何内容
这意味着在该节外部创建的变量在该节中不可用,并且在该节中创建的变量在该节外部不可用
因此,只能从节文件本身访问节
对象
现在说有一个解决办法 如果捕获整个部分:
{% capture section_item %}{% section 'your-section' %}{% endcapture %}
您将有权访问html部分。如果将内容输出为数据属性或其他易于从html中分离的内容,则可以获取所需的内容
例如:
{{section_item|split:'data image=“'| last | split:'”“| first}}
您将从名为data image
的数据属性中获取图像