CommerceForz

A Beginner’s Guide to Shopify Theme Blocks

  • Jojo Jacob
  • Last Updated - April, 2025

Shopify’s Theme Blocks are a powerful way to customize your storefront without diving deep into complex code. Whether you’re a developer or a store owner, understanding how to use ‘Theme Blocks’ can help you create a more dynamic and flexible shopping experience. In this guide, we’ll walk you through the basics of Theme Blocks and how to get started using Shopify’s own templating language called ‘liquid’.

🌟 What Are Theme Blocks?

According to Shopify, Theme Blocks are modular sections of content that can be added, removed, or rearranged in a Shopify theme. It allows you to create customizable layouts for your storefront, making it easier to tailor your store to your brand’s needs. Think of them as building blocks for your theme—each block serves a specific purpose, such as displaying a product, a banner, or a newsletter signup form.

Advantages of using Theme Blocks over normal liquid/HTML snippets:

✅ Flexibility: We can easily add or remove sections without touching the core theme code.
✅ Customizability : Allow store owners to customize their storefronts via the Shopify Admin without asking assistance of developers to create custom sections.
✅ Reusability: Create reusable blocks that can be used across multiple templates.
✅ Improved User Experience: Provide a more dynamic and engaging shopping experience for your customers.

Getting Started with Theme Blocks

To start using Theme Blocks, you’ll need to work with Shopify’s Liquid templating language. Liquid is a flexible and secure language used to load dynamic content in Shopify themes. Let’s dive into the basics.

Theme blocks are defined at the theme level, making them reusable across different sections of the theme. Unlike section-defined blocks that are confined to specific sections, theme blocks offer greater flexibility. Additionally, they can be nested within other theme blocks to create a structured content hierarchy, enhancing customization capabilities.

By the end of this tutorial, you will have a reusable text block that can be incorporated into various sections and blocks of the theme. Specifically, you will add it to a Custom Section and a Group block for enhanced flexibility.

1. Add a Blocks Folder

Theme Blocks are essentially Liquid files stored in the blocks directory of your theme. To create a new Theme Block, you’ll need to add a Liquid file to the /blocks folder within your theme.

If your theme doesn’t already have a /blocks folder, you’ll need to create one at the root level of your theme. Once the folder is set up, you can start adding block files. For example, you might create a file called text.liquid inside the /blocks folder to define a text-based block.

2. Write the Markup

Theme Block files consist of markup, which includes any HTML or Liquid content you want to display within the block. This markup defines how the block will appear and function on your storefront. You can use standard HTML for structure and styling, combined with Liquid for dynamic content and logic.

For example, if you’re creating a text.liquid block, you might include a combination of HTML for layout and Liquid for rendering dynamic text or settings.

blog-image
3. Write the Schema

Every Theme Block file includes a schema, defined using the {% schema %} Liquid tag. The schema is used to configure the block’s settings and attributes, such as text fields, image pickers, or dropdown options. These settings allow store owners to customize the block directly from the Shopify Admin without needing to edit the code.

The schema acts as the blueprint for your block, specifying what options are available and how they should be displayed. To define a block’s schema, you’ll use JSON-like syntax within the {% schema %} tag.

blog-image
4. Use Liquid Objects in Blocks

When working with Theme Blocks, you’ll use a few key Liquid objects to access and render dynamic content:

1. Block Object: Each Theme Block references a block object, which contains the properties and setting values specific to that block. For example, you can access a block’s settings using block.settings.

2. Section Object: Theme Blocks can also reference the section object of the section that rendered the block. This allows you to access settings or properties defined at the section level.

3. Global Objects: Blocks have access to global Liquid objects, such as shop, product, or collection, which provide additional context and data for your storefront.

For instance, in a Text block, you might reference the block.settings attribute to display the block’s configured text or other settings. Here’s an example:

blog-image
5. Add a Block Preset

To make a Theme Block available for merchants in the theme editor’s block picker, you need to define presets in the block’s schema. Presets act as predefined configurations for the block, allowing merchants to easily add and use the block in their store.
You can create multiple presets for the same Theme Block, each with its own default settings. For example, a Text block might have two presets: one called Text and another called Content. Here’s how you can define presets in the schema:

blog-image
6. Use Theme Blocks in Sections

Once you’ve defined Theme Blocks in your theme, the next step is to update your theme’s sections to render these blocks. This allows merchants to add, customize, and arrange blocks within the section using the theme editor.

7. Render the blocks in Liquid

Render the blocks in Liquid using :

blog-image
8. Update the Section Schema

To allow a section to accept all Theme Blocks, you can use the @theme type in the blocks attribute of the section’s schema. This makes the section compatible with any Theme Block defined in your theme. Here’s how you can do it:

blog-image

Advanced Features of Theme Blocks

Theme blocks offer additional customization options, including:
• Configurable Settings: Define custom settings for merchants.m.
• Block Targeting: Control where blocks can be used.
• Static Blocks: Keep specific blocks fixed within a layout.
• Dynamic Content: Connect blocks to dynamic data sources for personalization.

Conclusion

Shopify theme blocks provide a flexible and powerful way to customize store layouts dynamically. Whether you're a developer or a store owner, leveraging theme blocks allows you to improve content management, enhance design flexibility, and create a superior user experience.