Section scope across two page templates

Tourist
8 0 0

Hello, 

I was curious if the capabilities of sections allow for a section to be added to two different page templates but have different data populating it? Currently, I'm seeing the same data I entered in the section for page 1 on page 2. Is there some type of workaround or something that I might have missed?

Page 1:

{% section 'banner' %}

Headline field data entered: Hello Page 1

Page 2:

{% section 'banner' %}

Headline field data entered: Hello Page 2

 

I hope the only solution isn't to create multiple sections like banner-homepage.liquid, and banner-interior-page.liquid. 

0 Likes
Shopify Expert
622 32 128

Unfortunately, it's not possible. If you want to use theme sections, you would have to create one for each page you want to use it on. This isn't really a scalable solution, so you might want to consider building the banner with metafields instead.

It's worth noting that Shopify is actively revamping how this works, dubbed "Sections Everywhere", but there is no ETA for when it will be rolled out.

Tourist
8 0 0

Hi @gina-gregory

Thank you for your quick response. You're right this isn't ideal and makes for a bloated codebase. I can't wait for that feature to be rolled out.

You make mention of building the "banner" using metafields. Can you elaborate a little more on that? We do have the ACF plugin installed. This might be a dumb question but is there a limit to the number of sections that can be created and added to the project? 

0 Likes
Shopify Expert
622 32 128

You could create metafields that contain the page-specific settings you need, and then use that to build your banner.

<section class="banner" style="background-image: url({{ page.metafields.banner.image }});">
  <h2 style="color: {{ page.metafields.banner.title_color }}">{{ page.metafields.banner.title }}</h2>
</section>

 

Shopify Expert
622 32 128

There's not a specific number limit to how many sections that I know of, but there is a file size limit to the settings_data.json file, which is where the content for the sections is stored. This also demonstrates why sections are not scalable and available to use uniquely on every page.

Tourist
8 0 0

Hi @gina-gregory

Thanks again for taking the time to explain in great detail. 

0 Likes