Theme Development

Liquid Sections

Shopify Theme Sections

Liquid sections create reusable Shopify content blocks with schema.

Introduction to Liquid Sections

Liquid sections are a powerful feature in Shopify that allow developers to create reusable content blocks. These blocks are defined using Liquid, Shopify's templating language, and are configured with a schema to make them customizable directly from the Shopify admin panel. This capability makes it easier for merchants to manage their content without needing to dive into the code.

Defining a Simple Liquid Section

To define a Liquid section, you must create a new file in your theme's sections directory. The file should have a .liquid extension. Let's create a basic section called featured-product.

Understanding Schema in Liquid Sections

The schema tag in a Liquid section is a JSON object that defines the settings and blocks available in the section. It is used to specify the inputs available to the merchant, such as text fields, image uploads, or product selectors. In our featured-product example, we defined a single product selector that allows the merchant to choose a product to display.

Customizing Sections with Schema Settings

The settings defined within the schema are accessible within the Liquid template via the section.settings object. This allows you to dynamically customize the content and style of your section based on the merchant's selections in the Shopify admin.

Using Liquid Sections in Templates

Once your section is defined, you can include it in any template file using the {% include %} or {% section %} tag. This allows you to reuse the same section across multiple pages or templates.

Best Practices for Liquid Sections

  • Keep your schema definitions clear and concise.
  • Use comments within your Liquid files to document your sections.
  • Test your sections thoroughly to ensure compatibility across different themes.
  • Leverage the flexibility of Liquid to create dynamic, customizable content blocks.
Previous
Templates