我需要添加章节到一个页面。听我说。我知道这个话题已被击败,但我觉得我有答案,我只是不知道如何理解它。我的Shopify部分出现随机JSON错误?
I have been working hard to understand and implement the following tutorial in my client's store...... https://oak.works/blog/technical/2017/03/23/shopify-sections-editor/
我是全新的堆栈溢出,不是全新的Shopify或主题代码,但我很绿。所以,请把它容易对我......到目前为止,很多痛苦的研究,我已经确定(猜测),以下步骤是最有可能的途径,这将导致成功:
- making a new alternate page template, mine:
page.portfolio.liquid
- creating a snippet of the original section's code, just the top part (sans schema), mine:
snippet-collection-callout.liquid
- creating a new section, using the code (from the article) to render blocks into the section and calling the snippet for settings as shown in the tutorial I think? (BELOW, called
section-portfolio-page.liquid
)- defining the schema (copy and paste) from the original section
collection-callout.liquid
to the new section (BELOW, calledsection-portfolio-page.liquid
)- calling the section into the new page template
page.portfolio.liquid
with{% section 'section-portfolio-page' %}
- creating a new page in Shopify admin, "Portfolio Page"
- assigning the new alternate page template to
page.portfolio
and ensuring navigation is there- navigate to the new page through theme editor, which should show a static section that I can enter and customize via blocks.
但我m卡在步骤4,因为它踢着这个错误:
Error: Invalid JSON in tag 'schema'
我知道页面上的部分是可能的。但我想哭。任何人都可以看看下面的文章,我的步骤和代码,并将我推向正确的方向吗?如果我的某个步骤有些错误,或者甚至只是解释JSON错误的位置,请在阅读完本文后告诉我。
我约173小时试图弄清楚这一点,我的孩子没有感到好笑。不开玩笑。任何帮助将不胜感激......
Here is the original section I am trying to recreate and piece together, for use on a page:
{%- assign collection = collections[section.settings.collection] -%}
{%- assign isEmpty = false -%}
{% if section.settings.collection == blank %}
{%- assign isEmpty = true -%}
{% endif %}
{% if section.settings.divider %}<div class="section--divider">{% endif %}
<div class="page-width">
<div class="feature-row feature-row--small-none">
<div class="feature-row__item feature-row__callout-image">
<div class="callout-images {% if isEmpty %}blank-state{% endif %}" data-aos="collection-callout">
{% if isEmpty %}
{% for i in (1..5) %}
{% capture current %}{% cycle 1, 2, 3, 4, 5, 6 %}{% endcapture %}
<div class="callout-image">{{ 'product-' | append: current | placeholder_svg_tag: 'placeholder-svg' }}</div>
{% endfor %}
{% else %}
{% for product in collection.products limit: 5 %}
<img src="{{ product | img_url: '300x' }}" alt="{{ product.title }}" class="callout-image">
{% endfor %}
{% endif %}
</div>
</div>
<div class="feature-row__item feature-row__text feature-row__text--{{ section.settings.layout }} feature-row__callout-text larger-text">
{% if section.settings.subtitle %}
<p class="subtitle">{{ section.settings.subtitle }}</p>
{% endif %}
{% if section.settings.title != blank %}
<h2 class="h3">{{ section.settings.title }}</h3>
{% endif %}
<div class="rte">
{% if section.settings.text != blank %}
<p>{{ section.settings.text }}</p>
{% endif %}
</div>
{% if section.settings.cta_text1 != blank %}
<a href="{{ section.settings.cta_link1 }}" class="btn">
{{ section.settings.cta_text1 }}
</a>
{% endif %}
{% if section.settings.cta_text2 != blank %}
<a href="{{ section.settings.cta_link2 }}" class="btn">
{{ section.settings.cta_text2 }}
</a>
{% endif %}
</div>
</div>
</div>
{% if section.settings.divider %}</div>{% endif %}
{% schema %}
{
"name": "Collection callout",
"class": "index-section",
"settings": [
{
"type": "collection",
"id": "collection",
"label": "Collection"
},
{
"type": "text",
"id": "subtitle",
"label": "Subtitle",
"default": "Brand new"
},
{
"type": "text",
"id": "title",
"label": "Title",
"default": "Collection callout"
},
{
"type": "textarea",
"id": "text",
"label": "Text",
"default": "Use this section to easily call attention to one of your collections. We'll show photos of the first 5 products."
},
{
"type": "text",
"id": "cta_text1",
"label": "Button #1 text",
"default": "Shop Jackets"
},
{
"type": "url",
"id": "cta_link1",
"label": "Button #1 link"
},
{
"type": "text",
"id": "cta_text2",
"label": "Button #2 text",
"default": "Shop All Mens"
},
{
"type": "url",
"id": "cta_link2",
"label": "Button #2 link"
},
{
"type": "select",
"id": "layout",
"label": "Layout",
"default": "right",
"options": [
{
"value": "left",
"label": "Text on left"
},
{
"value": "right",
"label": "Text on right"
}
]
},
{
"type": "checkbox",
"id": "divider",
"label": "Show section divider",
"default": false
}
],
"presets": [{
"name": "Collection callout",
"category": "Collection"
}]
}
{% endschema %}
Here is the code for the new
section-portfolio-page.liquid
I am trying to save, but getting an error for:
<div>
{% for block in section.blocks %}
<div class="grid-item" {{ block.shopify_attributes }}>
{% case block.type %}
{% when 'callout' %}
{% include 'snippet-collection-callout' %}
{% endcase %}
</div>
{% endfor %}
</div>
{% schema %}
{
"blocks": [
{
"name": "Collection callout",
"class": "index-section",
"settings": [
{
"type": "collection",
"id": "collection",
"label": "Collection"
},
{
"type": "text",
"id": "subtitle",
"label": "Subtitle",
"default": "Brand new"
},
{
"type": "text",
"id": "title",
"label": "Title",
"default": "Collection callout"
},
{
"type": "textarea",
"id": "text",
"label": "Text",
"default": "Use this section to easily call attention to one of your collections. We'll show photos of the first 5 products."
},
{
"type": "text",
"id": "cta_text1",
"label": "Button #1 text",
"default": "Shop Jackets"
},
{
"type": "url",
"id": "cta_link1",
"label": "Button #1 link"
},
{
"type": "text",
"id": "cta_text2",
"label": "Button #2 text",
"default": "Shop All Mens"
},
{
"type": "url",
"id": "cta_link2",
"label": "Button #2 link"
},
{
"type": "select",
"id": "layout",
"label": "Layout",
"default": "right",
"options": [
{
"value": "left",
"label": "Text on left"
},
{
"value": "right",
"label": "Text on right"
}
]
},
{
"type": "checkbox",
"id": "divider",
"label": "Show section divider",
"default": false
}
],
"presets": [{
"name": "Collection callout",
"category": "Collection"
}]
}
{% endschema %}
谢谢!我会尽快尝试。出于好奇,你能否告诉我,如果你认为我在我计划采取的步骤中走在正确的轨道上? – kiefly
@kiefly开发中没有“正确”的轨迹,特别是Shopify。你编写代码以满足你的需求,每个开发者都有自己的方法。目前,你有一个带有'case'的裸露骨骼'for'循环,即没有太多的代码可以使用。你正在检查'block.type',但你没有一个块类型(你必须调用你的块'callout'而不是我为了让你的代码工作而输入的'collection')。总结起来,学习Liquid的基本语法和逻辑,稍后再为“正确”的方式担忧。 – drip
非常感谢您在这里的建设性反馈!对此,我真的非常感激。这给了我一个开始研究的地方。我想我只是想知道,我在这里概述的步骤是否似乎与本教程解释的步骤准确匹配/如果我正确理解说明?有些地方我不太清楚。为了澄清,您在顶部添加了'collection',将其标记为“type”而不是“class”,而我需要将其更改为'callout',对吗? – kiefly