Skip to main content

Welcome to a Grasp lesson

Create a free account to keep studying and create your own study path.

Lesson 29

Organizing the Theme Editor with Section Groups

Recommended resources

Hello! Welcome to your next lesson.

In our last session, we mastered presets, which are essential for making sections discoverable and providing merchants with a great starting point. However, as we create more and more specialized sections, the "Add section" list can become long and cluttered, leading to a confusing experience for the merchant.

This lesson tackles that problem head-on. Our learning outcome is to use section groups to organize the theme editor for a better merchant experience. By creating logical groupings for sections, you elevate your theme from a collection of components to a professionally organized and intuitive tool for your clients.

1. The "Why": From Disorganization to Structure

From your full-stack background, you know that a well-structured application is easier to navigate and use. The same principle applies to a Shopify theme's customization interface. Section groups serve two primary purposes that address fundamental architectural needs:

  1. Organization: They allow you to group related sections, decluttering the theme editor and guiding the merchant to add the right content in the right place. Instead of one long list, a merchant might see categories like "Header sections," "Footer sections," or "Promotional content."
  2. Scope and Persistence: They create distinct, global content areas (like headers and footers) that persist across multiple pages. This is different from sections added directly to a page template (like the homepage), which are specific to that template only.

This ability to structure the theme editor and create global content areas is a key feature of modern Shopify theme development.

Make Sections Really Everywhere With Section Groups

To understand the benefits from Shopify's perspective, please read this section from their Shopify Partners Blog. It clearly outlines the value proposition for both developers and merchants.

Read the section titled 'Why use section groups'. Pay close attention to the three main benefits: merchant flexibility, building more customizable themes, and seamless app integration.


2. The Anatomy of a Section Group

A section group is simply a JSON file that lives in the sections directory of your theme, right alongside the .liquid section files you've already been creating. While a .liquid file contains markup and logic, the group's .json file is pure data—it defines a list of sections and their order.

Shopify Theme Editor: Defining a Section Group in JSON
This image shows a typical `header-group.json` file. It's a data file that defines which sections belong to the "Header Group" and in what order they should appear.

Let's break down the essential schema for a section group.

Section groups

The official Shopify documentation provides the definitive schema for section groups. This will be our source of truth for understanding the required properties.

Review the 'Location' and 'Schema' sections of the documentation. Focus on the table that describes the four key attributes: type, name, sections, and order. Note the accepted values for the type attribute.

As you saw in the documentation, every section group JSON file must contain an object with four key properties:

  • name: A string that becomes the title for this group in the theme editor (e.g., "Header", "Footer", "Promotions").
  • type: This is critical for organizing and controlling sections. It can be a standard type (header, footer, aside) or a custom type you define, which must follow the format custom.<your-type-name> (e.g., custom.promo-banners).
  • sections: An object that will hold the data for any sections added to this group by the merchant. You can define "hard-coded" sections here, but it often starts empty to let the merchant customize it.
  • order: An array of section IDs, defining the rendering order. This also typically starts empty.

3. Creating and Rendering a Custom Section Group

Let's walk through the process of creating a new, custom area in our theme where a merchant can add promotional sections.

The process involves two steps:

  1. Define the group: Create a new JSON file in the /sections directory.
  2. Render the group: Use a Liquid tag to output the group in a layout file.

This video provides a clear, practical demonstration of these steps.

How to build custom Shopify sections (In-depth guide)

This clip from 'Coding with Robby' walks through creating a new section group from scratch and rendering it in the theme.

Watch from 15:54 to 17:16. Follow along as he creates a special-section.json file, defines the four required properties (including a custom type), and then renders it in theme.liquid using {% sections 'special-section' %}.

To recap the video's steps:

  1. Create the file: In your theme's sections folder, create a new file named promo-group.json.

  2. Add the schema: Populate it with the basic structure.

    // sections/promo-group.json
    {
      "name": "Promo Banners",
      "type": "custom.promo",
      "sections": {},
      "order": []
    }
    
  3. Render in the layout: Open your layout/theme.liquid file. Find a suitable place (e.g., above the main content) and add the Liquid tag.

    // layout/theme.liquid
    ...
    {% sections 'header-group' %}
    
    <main id="MainContent" class="content-for-layout" role="main" tabindex="-1">
      {% sections 'promo-group' %}
      {{ content_for_layout }}
    </main>
    
    {% sections 'footer-group' %}
    ...
    

After saving these files, you will see a new "Promo Banners" area in your theme editor, ready for sections to be added. But which sections?


4. Controlling Section Availability for a Better UX

Right now, any section with a preset can be added to our new "Promo Banners" group. This isn't ideal. A "Featured Product" section probably doesn't belong there. This is where we deliver on the promise of a better merchant experience.

We can control where a section can be added by modifying the section's .liquid file schema with two powerful properties: enabled_on and disabled_on.

Impact of Section Groups in Shopify Theme Editor
As this image illustrates, you can use section properties to filter the "Add section" list, ensuring merchants only see relevant options for the group they are editing.

Let's see this in action. Imagine we have a section file, promotional-banner.liquid. To ensure it can only be added to our new custom.promo group, we would add an enabled_on property to its schema:

// in sections/promotional-banner.liquid
{% schema %}
{
  "name": "Promotional Banner",
  "settings": [ ... ],
  "enabled_on": {
    "groups": ["custom.promo"]
  },
  "presets": [
    {
      "name": "Promotional Banner"
    }
  ]
}
{% endschema %}

Conversely, if we wanted to prevent our "Featured Collection" section from ever appearing in the header or footer, we would use disabled_on:

// in sections/featured-collection.liquid
{% schema %}
{
  "name": "Featured Collection",
  "settings": [ ... ],
  "disabled_on": {
    "groups": ["header", "footer"]
  },
  "presets": [ ... ]
}
{% endschema %}

This next video clip demonstrates this exact technique.

How to build custom Shopify sections (In-depth guide)

Building on the last clip, this segment shows how to use the enabled_on property to restrict a section to the custom group we just created.

Watch from 17:16 to 17:55. Notice how he modifies the section's schema with enabled_on and specifies the group's custom type. The result is that the section is no longer available in the main template area but can now be added to the new custom section group.

Test your understanding!

You have a section file named newsletter-signup.liquid. You want to ensure that merchants can only add this section to a section group with the type of footer. What would you add to the schema inside newsletter-signup.liquid to achieve this?

Show answer

You would add the enabled_on property to the schema, specifying the footer group type.

"enabled_on": {
  "groups": ["footer"]
}

This tells Shopify that this section is only enabled for placement within groups of type "footer", effectively hiding it from all other "Add section" lists (like the header or main page template).


Conclusion

You've now learned how to impose structure and logic onto the theme customization experience. By moving beyond a flat list of sections and creating curated groups, you are building a more robust, professional, and user-friendly product for your clients.

Key Takeaways:

  • Section groups are JSON files in the /sections directory that define named, typed containers for sections.
  • They are rendered in layout files (like theme.liquid) using the {% sections 'group-name' %} tag, making their content appear globally across pages using that layout.
  • The primary way to organize the theme editor is by using the enabled_on and disabled_on properties within a section's schema.
  • By specifying groups within these properties, you gain fine-grained control over which sections a merchant can add to which group, dramatically improving the user experience.

In this lesson, we controlled where sections can be placed. In our next lesson, we'll shift our focus to controlling the content inside a section. We will learn how to render section content conditionally based on user-configured settings, allowing us to build even more dynamic and flexible components.