Many Online Store 2.0 features rely on [JSON templates](/docs/storefronts/themes/architecture/templates). You can migrate your theme to add support for these features by converting a Liquid template into a JSON template, and moving any required Liquid code or HTML into sections that you can include in the new JSON template. In this tutorial, you'll move the code from a Liquid template file into a section file, and then include that section file in a new JSON template. You'll also add support for app blocks to your sections. This tutorial uses Debut as an example, and moves code from a `product.liquid` template file into a `product-template.liquid` section file, which can then be included in a new `product.json` template. You can perform all of these steps using [Shopify CLI](/docs/storefronts/themes/tools/cli/cli-2/commands) or the [code editor](/docs/storefronts/themes/tools/code-editor).
## Requirements Before you start, do the following: - Identify the theme that you want to migrate. - If you want to migrate your theme using your local development environment and Shopify CLI: - [Install](/docs/api/shopify-cli) Shopify CLI. - Make sure that you have a [collaborator account](/docs/storefronts/themes/tools/collaborator-accounts) or a [staff account](https://help.shopify.com/manual/your-account/staff-accounts) for the store you want to work on, or you're the owner of the store. If you have a collaborator account or staff account, then you must be granted the **Manage themes** permission or **Themes** permission for the store. Store owners have these permissions by default. - Note the URL of the store that you want to work on. ## Step 1: Back up the theme After you identify the theme that you want to work on, make a copy of it. If you're editing the theme using the code editor, then [duplicate](https://help.shopify.com/manual/online-store/themes/managing-themes/duplicating-themes) the theme. Make sure that the theme is unpublished while you're editing it. This is because you'll be removing files from the theme, which would impact the live storefront. You might also need a back-up copy to reference or revert to later. If you're editing the theme locally using Shopify CLI, then download the theme files using the [`shopify theme pull`](/docs/api/shopify-cli/theme/theme-pull) command. ## Step 2: Identify sections and remove section references To start converting your Liquid template into a JSON template, you must make note of and then remove any `{% section %}` tags. You need to remove these references so that you can move the rest of the code into a section file. Section files can't contain references to other section files. 1. Open your theme in the code editor or your local development environment. 2. Locate the `product.liquid` file in the `/templates` directory. 3. Search for any `{% section %}` tags where sections are being included. Note their names and where they are located. For example, in Debut, there are two sections included at the top of the template: ```liquid {% section 'product-template' %} {% section 'product-recommendations' %} ``` The first section tag references the `product-template` section, which contains most of the markup needed to render the product page. That includes the product title, product images, add to cart button, and more. Next is a reference to the `product-recommendations` section, which displays a list of products automatically selected as suggestions for customers. 4. After you've found any `{% section %}` tags and made a note of their location, delete the tags from the `product.liquid` file. ## Step 3: Move code from the template into a section After you remove the `{% section %}` tags from the template code, you need to decide where to move it. You can move this code to an existing section or a new section. ### Option 1: Add code to an existing section You might already have a section that renders a large portion of the code for a page. For example, in Debut, the `product-template` section contains a portion of the code for the product page. 1. Open the section file where you want to add the template code. 2. Copy the remaining code from `product.liquid`. 3. Paste the code into the section file above the opening `{% schema %}` tags. ### Option 2: Add code to a new section If none of the existing section files in your theme are appropriate, then you can create a new section to host your Liquid template code. 1. Create a new file in the `/sections` directory. For example, `product-content.liquid`. If you're creating the section through the code editor, then delete the placeholder code for the section. 2. After you create your new section file, copy the remaining code from the `product.liquid` file and paste it into the empty section file. ## Step 4: Delete the Liquid template file After you copy the code from `product.liquid`, delete `product.liquid` from the `/templates` directory. This is because it will be replaced with a `product.json` file, and a `product.liquid` and `product.json` file can't be stored in the `/templates` directory at the same time. ## Step 5: Create a JSON template file After the `product.liquid` file has been deleted, you can create the replacement JSON template. 1. Create a new file in the `/templates` directory called `product.json`: - If you're using the code editor: 1. Select **Add a new template**. 2. From the **Create a template for** drop-down menu, choose **Product**. 3. Select **JSON** as the template type. - If you're editing the theme locally, then create a new file called `product.json` and save it in the `/templates` directory. 2. After you create the `product.json` file, replace any default code inside this file with the following: ```json { "sections": { "main": { "type": "product-template" } }, "order": [ "main" ] } ``` The `type` property should reference the name of the section file where you transferred the markup of the product template file in step 3. 3. Save the file. ## Step 6: Test the template After you create your new template, open it in the theme editor to make sure that it renders correctly. To access the theme editor using Shopify CLI: 1. In a terminal, type `shopify login --store