Create alternate templates

Creating an alternate template allows you to modify the way content is shown on your online store, but only for the products, collections, blogs, and other pages that you apply the alternate template to. For example, you can create an alternate product template that has no add to cart button, and apply it only to products that are not for sale. Or, you can create an alternate page template that doesn’t include a header, and apply it to a selection of your store’s pages.

Create a new template file in your theme

  1. Find the theme you want to edit, click Actions, and then click Edit code.

  2. In the Templates directory, click Add a new template.

    Add new template
  3. Choose a type option for your new template. For example, for an alternate product template, select product. Give your template a meaningful name, which will make it easy to find when you are assigning it in the admin. For example, an alternate product template with no prices or add to cart button might be called not-for-sale.

    Create new template
  4. Click Create template. Your new template will open in the code editor, and the file will be populated with default code.

  5. Depending on your theme and the type of template that you have created, you might need to create a new section file as well. If your new template contains the code that you want to edit, then creating a section won't be necessary. In this case, you can simply edit your new template as needed, and move on to the next step.

    If your new template includes a Liquid tag for a section that contains the code that you want to edit, then you will need to create a new section. For example, if you are creating an alternate product template, then you will need to create a new section, since most of the code that makes up the product page is stored in a section file, rather than a template file.

    In your new template file, find the Liquid tag for the section that you'd like to edit, and replace the name of the section with the name that you will give your new section. For example, the product template contains the following Liquid tag:

    {% section 'product-template' %}
    

    Replace product-template with the name of the new section that you will create next. For example, if you call your new section product-not-for-sale-template, then your code should look like this:

    {% section 'product-not-for-sale-template' %}
    
  6. Click Save. If you do not need to create a new section to make your edits, then you can skip the next section.

Create a new section file in your theme

  1. In the Sections directory, click Add a new section. Give your section the same name that you used in the Liquid tag for your new template file:

    Product not for sale template

  2. Click Create section. Your new section will open in the code editor, and will be populated with some default code. Delete the default code, so that the file is empty.

  3. The next step is to copy and paste code into your new section file from an existing section in your theme. For example, if you are creating an alternate product template, then you will click to open product-template.liquid, and copy the entire contents of the file. Return to your new and empty section file, and paste in the code you have copied.

  4. Edit your new section file as needed.

  5. Click Save.

Assign your template in the admin

After you have created an alternate template, it will appear in your admin. You will see a Theme templates section in the sidebar of the appropriate admin page. For example, if you have created a new product template, a Theme templates section will be visible when you click to view, create, or edit a product. You can assign the template that you want to use for each product from the Template suffix list.

Template drop down on product page

Tip

The Theme templates section won't appear on the product page unless your theme has more than one product template. If you don't see the Theme templates section after creating a new template, it's possible that you have created a template of a different type. For example, you might have created a page template instead of a product template.

Only templates present in your published theme will be available in the Theme templates section.

Create a new template file in your theme

  1. Find the theme you want to edit, click Actions, and then click Edit code.

  2. In the Templates directory, click Add a new template.

    Add new template
  3. Choose a type option for your new template. For example, for an alternate product template, select product. Give your template a meaningful name, which will make it easy to find when you are assigning it in the admin. For example, an alternate product template with no prices or add to cart button might be called not-for-sale.

    Create new template
  4. Click Create template. Your new template will open in the code editor, and the file will be populated with default code.

  5. Edit your new template as needed.

  6. Click Save.

Assign your template in the admin

After you have created an alternate template, it will appear in your admin. You will see a Theme templates section in the sidebar of the appropriate admin page. For example, if you have created a new product template, a Theme templates section will be visible when you click to view, create, or edit a product. You can assign the template that you want to use for each product from the Template suffix list.

Template drop down on product page

Tip

The Theme templates section won't appear on the product page unless your theme has more than one product template. If you don't see the Theme templates section after creating a new template, it's possible that you have created a template of a different type. For example, you might have created a page template instead of a product template.

Only templates present in your published theme will be available in the Theme templates section.

Want to discuss this page?

Visit the Shopify Community