I am new to Shopify and just started to learn. My problem is, I have created a page template with section which allow to section product, now when I create another page with same page template the page content was same that I have created before, if I change content in second page it will reflect to both pages. How I distinguish sections for different pages?
Section 1
{% schema %}
{
"name": "Page Heading",
"settings": [
{
"type": "text",
"id": "page-heading",
"label": "Page Heading"
},
{
"type": "text",
"id": "page-heading-big",
"label": "Bigger Heading"
},
{
"type": "image_picker",
"id": "page-heading-image",
"label": "Heading Image"
}
]
}
{% endschema %}
Section 2
{% schema %}
{
"name": "Promotional Blocks",
"max_blocks": 10,
"blocks": [
{
"type": "single-product",
"name": "Add Single Product",
"settings": [
{
"id": "single-product",
"type": "product",
"label": "Choose Product"
}
]
}
]
}
{% endschema %}
You are not doing anything wrong, but at the moment this is not possible in Shopify. According to Shopify Theme Docs
Sections can be statically included in a theme's templates (like the header and footer), or they can be dynamically added to the theme's home page from the theme editor.
Static sections
You can include a section in a template file using the section tag. This tag behaves like the include tag for snippets: {% section 'header' %} will include the section located at sections/header.liquid. By explicitly calling a section this way, it is referred to as being static.
A section can be included in multiple templates, but there exists only one instance of that section. When a merchant changes the configuration of a static section in one place, that change will apply to all other places where the section is included. Note that sections cannot include other sections.
So a possible solution is to create a new section with same settings in your theme files.
Another possible workaround as defined here
Shopify one section / schema for multiple pages : Dynamic sections
This approach uses, Shopify Blocks inside sections.
Sections can define blocks in their schemas. Blocks are containers of settings and content which can be added, removed, and reordered within a section.
What it does is create a block inside section and add additional setting named page_handle. So anytime a user adds the new block, user is able to select on which page the block should be displayed. Then in section code, it checks if the page_handle selected inside block setting matches the page_handle that user is currently viewing. If yes then show the content.
{% comment %}
block.settings.page_handle is what user selected in block settings
page_handle is what page user is viewing on Shopify site
{% endcomment %}
{% assign page_handle = page.handle %}
{% if block.settings.page_handle == page_handle %}
{{ block.settings.page_title }}
{% endif %}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With