How can I have unique content in each section per page in OS 2.0?

How can I have unique content in each section per page in OS 2.0?

nickkos
Shopify Partner
7 0 6

So I did a conversion of my site to OS 2.0 a while back. One of the intriguing things about OS2 is the changes made to section templates, with the ability to have a section repeat itself in multiple instances.

However, in practice I have found either an incredibly stupid limitation, or an unintuitive interface.

I have a page template called bio.page.json. Inside that renders the bio-section.liquid section file. I have 20-30 "bio page" templates. However the section file is not "reusable" on a per page basis. Once the customizer content is edited for that section it applies to every single page with the bio template. I thought one of the use cases of section everywhere was to eliminate the need to create a ton of files for reusable content.

Am I missing something? I want unique content in each section per page!!!

Replies 4 (4)

iDoThemes
Trailblazer
207 43 93

I've used this without issue so it should work.

Are these sections you've created yourself? It's possible you missed some attributes from the main section file div, like:

<div data-section-id="{{ section.id }}" data-section-type="header-section">

 Or 

<section class="section--featured-collection" id="section-{{ section.id }}">

 

Though i'd have thought these would be autofilled if not present. What does the data structure of your new .json template look like? If it's correctly creating unique IDs you should see something like
Bed Threads ~ Edit ~ [Dev] Byob Table Luke ~ Shopify 2021-08-04 15-29-53.png

Where each key inside the sections object has a unique name where the data for that section is stored. 

Developer of Liquify Chrome Extension -- Enhance the Shopify Theme Code Editor
.




Theme Developer -- Drop me a line
cdennington
Shopify Partner
3 0 1

@nickkos Did you find a fix for this?

It seems to me the issue is still present, I have one collection.json file which is the default collection template, if I go into customise and add a section to one of my collections it then appears on all collections which are using the collection.json file as their template.

I was expecting with 2.0 if I add a section to any page, product, collection it would be specific to that page and not specific to the template. 

All of my sections have a unique ID like:

data-section-id="{{ section.id }}"

I'm also not including them statically, and I can add them to any page

In my .json template file, I can see the section id and name, as per your comment @iDoThemes 

cdennington_0-1636553047689.png

 

Seems to me as the data is stored in a single template file, its specific to that template and not the individual pages that use that template, which is basically how thing worked < 2.0. Which is a shame!

This also seems to be the case using the default Dawn theme, if you create two pages that use the same default page template, they inherit the sections added from each other. But if you add a contact page which uses the contact template, then the sections are separate. 

Is there a fix for this? Or does Shopify plan to fix this? I guess once metafields are rolled out for collections, I can just use those. 

 

axis80
Shopify Partner
23 1 9

Within the theme customizer you can create a new template - for example, collections-alternate and then add the block only to that.  Then you can assign certain collections to use that template.

Ben31
Trailblazer
209 8 153

@cdennington Did you find a solution for this?

 

Because in my experience this is a really dumb situation where you end-up with endless templates, one for every page where you want page-specific content - which is what 95% of website is! 

 

What we want is endless pages, not endless templates.