Professional Documents
Culture Documents
Join now
Show
Home
Web Design and Development Blog
How to Create Your First Shopify Theme Section
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 1/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
Visit docs
Giving your clients creative control is key, especially when they want the
ability to customize their storefront. Shopify’s sections feature is a powerful
tool for personalizing Shopify themes, so using them efficiently and following
best practices will unlock a range of options for your clients.
In this article, we’ll cover how to get started with creating different types of
theme sections, and the rules for using them, so that you can help empower
your clients to customize their store. We'll also explore some examples of
specific sections from our source-available Dawn theme, to demonstrate
exactly how you can use them in real world scenarios.
Sections are contained within the /sections directory of a theme, and can
be statically included in a theme's layout files (like the header and footer), or
they can be dynamically added to any template from the Theme Editor. To get
a sense of the various components which can be represented as sections, you
can explore the /sections directory of the Dawn theme.
With the launch of Online Store 2.0, sections can now be used as the primary
way to organize all the different aspects of your theme, from whole pages, to
individual elements. As we'll cover in this article, the ability to add sections to
any JSON templates will allow you to easily arrange different pages, which can
be further enhanced when merchants customize their theme.
These JSON templates don't include any markup or Liquid objects for
displaying store content, they are simply data files that indicate which
sections will appear by default on a page, and in what order.
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 3/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
1 {
2 "name": "Product",
3 "sections": {
4 "main": {
5 "type": "main-product"
6 }
7 },
8 "order": [
9 "main"
10 ]
11 }
product.json
hosted with ❤ by GitHub view raw
In this case, a product page would render with a section called main-
product.liquid , and it would be the only section appearing by default.
When a merchant customizes this page, and adds more sections to the page,
the product.json template file would be updated with this information.
We'll be exploring this process more in this article when we look at how
sections are included in templates.
Basics of sections
When developing your theme using sections and JSON templates, you can
consider building section files in two distinct categories: "main" page
sections, and individual modular components.
Within a main page section, you should include all the default content for that
page. For example, in the main section for a product page, you would include
the important elements to display a product and its associated properties
such as product title, description, media, price, and the add-to-cart form.
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 4/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
You can access Liquid variables, or objects, within a section, based on which
page template a section is included in. This means that a section that will be
rendered within a product.json template will be able to access any
attributes of the product Liquid object, representing the product whose
page is being rendered.
Since a main page section includes markup specific to one type of page,
you'll only want to include it within its associated template. To prevent a main
page section from being added to other page types from the theme editor, it
should not contain presets
preset within its section schema.
To view an example of a main page section, you can explore the main-
product.liquid file in the /sections directory of Dawn, or any of the
sections that are prefixed with main in the title. As a general rule, you
should also name your main page sections with main in the title to help you
distinguish between different section types.
Modular sections
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 5/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 6/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 7/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
The templates attribute accepts a list of strings that represent the page
type.
Section settings
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 8/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
We've looked briefly at how a section file's settings can be used to create
customization options that merchants can access, but let's dive into these a
little deeper, to see how they're constructed.
As we've seen, settings are included within section files, inside {% schema
%} tags, which denote that these are settings that should render on the UI of
the theme editor. A very simple example of this could be seen with a custom
text section that could look something like:
1 <div class="custom-text-section">
2 <h2> {{ section.settings.custom_text_title }} </h2>
3 <div>{{ section.settings.custom_text_body }}</div>
4 </div>
5
6 {% schema %}
7 {
8 "name": "Text Box",
9 "settings": [
10 {
11 "id": "custom_text_title",
12 "type": "text",
13 "label": "Text box heading",
14 "default": "Title"
15 },
16 {
17 "id": "custom_text_body",
18 "type": "richtext",
19 "label": "Add custom text below",
20 "default": "<p>Add your text here</p>"
21 }
22 ]
23 }
24 {% endschema %}
custom-text.liquid
hosted with ❤ by GitHub view raw
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 9/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
Below the HTML and Liquid markup we have our section settings, contained in
our {% schema %} tags. Each setting is represented by an object, where
we can define the setting id , its type and how it will appear on the editor.
To access a section's setting in Liquid, append its id to the
section.settings liquid object. We also define the type of setting it is
and how it will appear on the theme editor.
In this example, I’ve created a text box for our heading and a richtext
box for our body, but you could add a wide range of output types, depending
on your client requirements. Other valid input types include image_picker ,
radio , video_url , and font_picker .
This example is now a valid section, however we're missing one key aspect:
determining where exactly the section will appear on the theme. We'll explore
a few different approaches for including sections later, but for now we'll allow
the section to be added via the theme editor to any page by creating presets
preset
in the section.
Presets are default configurations of sections and are added within a section's
Preset
{% schema %} tags. In our simple example, the presets
preset could look like:
"presets":
preset [
"name": "custom-text",
"category": "Custom"
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 10/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
Once added to our example, the custom text-box section would look like:
1 <div class="custom-text-section">
2 <h2> {{ section.settings.custom_text_title }} </h2>
3 <div>{{ section.settings.custom_text_body }}</div>
4 </div>
5
6 {% schema %}
7 {
8 "name": "Text Box",
9 "settings": [
10 {
11 "id": "custom_text_title",
12 "type": "text",
13 "label": "Text box heading",
14 "default": "Title"
15 },
16 {
17 "id": "custom_text_body",
18 "type": "richtext",
19 "label": "Add custom text below",
20 "default": "<p>Add your text here</p>"
21 }
22 ],
23 "presets":
preset [
24 {
25 "name": "custom-text",
26 "category": "Custom"
27 }
28 ]
29 }
30 {% endschema %}
custom-text.liquid
hosted with ❤ by GitHub view raw
Now, if we navigate to the theme editor, and select Add section on any page,
this section will appear as an available option. The section settings we've
created will appear on the right sidebar with the labels and default text we've
added, and we can populate the input text settings, which will be displayed
on our section.
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 11/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
This is a simple example that shows the relationship between section settings
and variables that you can create within sections, as well as how these render
on the theme editor. For a more advanced model you can explore the rich text
section of the Dawn theme.
When we looked at main page sections, we saw that JSON template files
accept a "main" property, which becomes the default section for that page
type, and should include all the important content elements for that page.
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 12/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
1 {
2 "name": "Product",
3 "sections": {
4 "main": {
5 "type": "product-template"
6 },
7 "recommendations": {
8 "type": "product-recommendations"
9 }
10 },
11 "order": [
12 "main",
13 "recommendations"
14 ]
15 }
product.json
hosted with ❤ by GitHub view raw
Since this JSON template is referencing more than one section, we need to
define how the sections appear sequentially, within the order object. Every
section included in a JSON template will need to be assigned a default order,
however merchants can still rearrange the sections on the theme editor.
As we saw with our custom text, it's possible to make a section available on all
pages of a theme when presets
preset are present within the schema settings.
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 13/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
"presets":
preset [
"name": "custom-text",
"category": "Custom"
This drag and drop functionality means that when you build custom dynamic
sections, a wide range of options for personalizing stores will be unlocked.
You can create movable sections for video, products, or image galleries. A
good example of a section using this method would be Dawn's newsletter
section.
The Liquid section tag allows you to render a section from the
/sections directory in a Liquid layout or template file. This tag could
appear as:
{% section 'header' %}
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 14/20
12/30/21, 1:35 AM How to Create Your First Shopify Theme Section — Shopify Theme Development (2021)
This approach is most commonly used for content and components that
should always be visible such as headers, footers and announcement bars. To
see an example of this on Dawn, you can check out the theme.liquid file
where the static announcement bar, header section and footer sections are
added with the section tag.
Empowering creativity
Now that you’ve seen how to create and add sections to your themes, you can
build endless options for your clients’ stores.
Working with JSON templates unlocks the power of sections for all pages of a
theme, which will allow merchants to build their store exactly how they would
like—with some direction from you.
Sign up
https://www.shopify.com/partners/blog/how-to-create-your-first-shopify-theme-section 15/20