Confused about dynamic sections

Solved
tony5280
Shopify Partner
61 6 18

Hi, I'm a seasoned dev, but new to shopify. 

I have a section of my client's site dedicated to services. Many of the services will need unique forms, and the client would like the ability to upload 3 images per service page. 

It seemed to me that I should create a specific services template, and apply that to the services pages. I set out to create a formbuilder and image upload sections, with the schema in sections/services.liquid, and the layout in templates/page.services.liquid.

I uploaded the files, and naved over to the page, let's call it 'service 1'. In the bottom right, I hit customize, so that I could get to the "theme editor" view with wysiwg window in center, and sections sidebar down the left. I uploaded a few images, and configured the form fields for that page. GREAT!

Then I went to the 'service 2' page, and I realized that the section settings had carried over from 'services 1'. 

Is there any way to enable editable sections in the page that are unique to THAT PAGE, rather than global???

0 Likes
tony5280
Shopify Partner
61 6 18

here's an example. 


sections/imagepicker.liquid

 

 

<!-- imagepicker.liquid -->
{% schema %}
{
	"name": "Images",
	"max_blocks": 3,
	"blocks": [
		{
			"type": "image",
			"name": "Featured Image",
			"settings": [
				{
					"id": "imagep",
					"type": "image_picker",
					"label": "Image"
				}
			]
		}
	]
}
{% endschema %}

 

 

templates/page.services.liquid includes the imagepicker section:

{% section 'imagepicker' %}

When I navigate to the front end of a page using this template, and hit 'customize', I see the imagepicker. If I set some images, then apply the page.services template to another page, the new page inherits the previously set images (well, rather, it repurposes the same section object). If I modify those images, those changes are reflected in the original page. It seems the section settings are applied globally. How can I enable one imagepicker section to define unique sets of images for different pages? Do I need some sort of section template?

 

0 Likes
tony5280
Shopify Partner
61 6 18

Anyone?

0 Likes
JØhn
Excursionist
37 5 9

This is an accepted solution.

Hey @tony5280, a more dynamic sections architecture is on the way, but at the moment, if you include a section on a page, its settings persist across all versions of it, and anywhere else that section is included - except the homepage, that one's unique.

My workaround is to implement override blocks, where each block has a setting for a url/handle it should apply to, and if you're on that page, you use the block settings rather than the global settings. So you could have a generic image in the section, but collection-specific images in the blocks. Something like:

 

{% if collection.handle == block.settings.handle %}
  {{ block.settings.image }}
{% else %}
  {{ section.settings.image }}
{% endif %}

 

 

tony5280
Shopify Partner
61 6 18

That's really interesting!

0 Likes