How URLs Map to Shopify Templates

One of the (many) features I love about working with Shopify Themes is the simple folder structure. Each store can be powered by a single layout file and a handful of templates meaning you can achieve a lot with a little — power in simplicity.

However if you are new to Shopify Themes, you may not know exactly when each template gets rendered, or be aware that the same template gets used in various places around the store.

We've already looked at how to use both alternate layout and template files, therefore in this article we'll turn our focus to understanding under what conditions each template is rendered in a store.

URL template mapping

Internally, Shopify has its own routing table which determines which template is displayed based on the URL requested by the user. If you have ever used one of the popular development frameworks, you might be familiar with the concept of URL routing. Put simply it's a way of determining which template to send to the browser based on the requested URL.

I mentioned earlier that there are only a handful of templates required to power a store. Each of these templates serves one or more URL — in other words, we are able to utilise the same templates for multiple URLs. From a design perspective, this enables us to reduce our overhead when building a new store.

Password protected

You might have noticed that the password.liquid template is not included in the list. This template is only seen if you choose to password protect your storefront and as such will override all other URLs.

If your store is password protected and you do not have a password.liquid template in your theme, Shopify will render it's default password login page instead.

Alternate templates

It's also worth remembering that the above routing table can be affected by alternate templates — something we have covered in a previous tutorial.

URL parameters

As you will see above, a number of the routes have elements of the URL path wrapped in { }. I have included this to denote a variable which will have an impact on the data loaded into a template.

For example, if we take the /collections/{collection-handle} URL pattern a different set of data will be loaded into the template and sent to the browser if we requested /collections/bikes compared to /collections/cars.

You will also notice that a number of different URL patterns share the same template file, e.g /products and /collections will both render the list-collections.liquid template. Likewise /collections/, /collections/{collection-handle}/ and /collections/{collection-handle}/{tag} all make use of collection.liquid.

Final note

If you are ever unsure which template is being rendered, there's a really simple way to check.

All you need to do is add {{ template }} to your theme.liquid file and start browsing your store. This global Shopify variable will output the currently rendered template minus the .liquid extension. It's a neat way to be doubly sure your templates are working as expected.

Here's a handy snippet that you can use in your own theme development with the output shown in the screenshot below:

Thanks for subscribing

About the Author

Keir is based in the UK and works on the Marketing Team at Shopify. You can read his latest articles on his personal blog, listen to his podcast, follow him on Twitter, or check out his travel and everyday carry review site Leader of the Pack.