Skip to main content

Theme Structure

The project structure generated by Nx-Shopify differs in a great manner with what you are used to with themekit. Despite it was built with ease-of-use in mind, here is an explanation of the main differences with a plain themekit project.

This is the general project structure you will find in a Nx-Shopify theme.

apps/my-theme/src
โ”œโ”€โ”€ assets
โ”œโ”€โ”€ config
โ”œโ”€โ”€ core
โ”œโ”€โ”€ environments
โ”œโ”€โ”€ locales
โ”œโ”€โ”€ theme
โ”‚ โ”œโ”€โ”€ layout
โ”‚ โ”œโ”€โ”€ sections
โ”‚ โ”œโ”€โ”€ snippets
โ”‚ โ””โ”€โ”€ templates
โ””โ”€โ”€ main.ts

Assets#

All the assets content will be placed inside this directory. You can organize your assets using as many subdirectories as you want (can be nested).

apps/my-theme/src/assets
โ”œโ”€โ”€ favicon
โ”œโ”€โ”€ fonts
โ”œโ”€โ”€ images
โ”‚ โ””โ”€โ”€ example.png
โ””โ”€โ”€ svg
โ””โ”€โ”€ example.svg

The theme build output will flatten all the files into a single assets directory. The above example will generate the following output:

dist/apps/my-theme/assets
โ”œโ”€โ”€ (... css files)
โ”œโ”€โ”€ (... js files)
โ”œโ”€โ”€ example.png
โ”œโ”€โ”€ example.svg
โ””โ”€โ”€ ...
warning

Knowing this, you should take special care on not using the exact same name for more than one file inside the src/assets directory or subdirectories as only one of them will go through the build process.

Using assets#

As mentioned above, it does not matter how you organize your assets files at source code level, the output result for any asset will always be assets/<asset name>. So, in order to use assets in your theme code you should not take into account it's subdirectories.

For example:

Given this images:

apps/my-theme/src/assets
โ””โ”€โ”€ images
โ”œโ”€โ”€ example.png
โ””โ”€โ”€ product-page
โ””โ”€โ”€ pdp-banner.png

Then, in your liquid code:

// โŒ Bad
<img src="{{ 'images/example.png' | asset_url }}" />
<img src="{{ 'images/product-page/pdp-banner.png' | asset_url }}" />
// โœ… Good
<img src="{{ 'example.png' | asset_url }}" />
<img src="{{ 'pdp-banner.png' | asset_url }}" />

Core#

apps/my-theme/src/core
โ”œโ”€โ”€ ...
โ”œโ”€โ”€ theme-bootstrap.ts
โ”œโ”€โ”€ theme-context.ts
โ”œโ”€โ”€ theme-module.ts
โ””โ”€โ”€ ...

The core directory contains essential TypeScript files related to how the theme is initialized once is loaded into a web browser.

tip

Learn more about the theme is initialized in the Theme Bootstrap Process doc.

Environments#

apps/my-theme/src/environments
โ”œโ”€โ”€ environment.prod.ts
โ””โ”€โ”€ environment.ts

All the TypeScript environment files will be placed in this directory.

tip

Learn more about working with environments in the Environments Guide.

Theme#

The src/theme directory contains all the theme blocks separated in their respective subdirectory

apps/my-theme/src/theme
โ”œโ”€โ”€ layout
โ”œโ”€โ”€ sections
โ”œโ”€โ”€ snippets
โ””โ”€โ”€ templates

Each block (layout, template, section or snippet) is composed by 3 files:

  • Liquid file (.liquid)
  • TypeScript file (.ts)
  • Styles file (.sass)

You can have any amount of blocks organized in as much subdirectories as you need in order to have a structured code base that suits your needs.

You could, for example, organize your snippets according to where they are designed to be used:

apps/my-theme/src/theme/snippets
โ”œโ”€โ”€ index
โ”‚ โ”œโ”€โ”€ hero-slider
โ”‚ โ”‚ โ”œโ”€โ”€ hero-slider.liquid
โ”‚ โ”‚ โ”œโ”€โ”€ hero-slider.snippet.scss
โ”‚ โ”‚ โ””โ”€โ”€ hero-slider.snippet.ts
โ”‚ โ””โ”€โ”€ special-promo-news
โ”‚ โ”œโ”€โ”€ special-promo-news.liquid
โ”‚ โ”œโ”€โ”€ special-promo-news.snippet.scss
โ”‚ โ””โ”€โ”€ special-promo-news.snippet.ts
โ”œโ”€โ”€ index.ts
โ”œโ”€โ”€ product
โ”‚ โ”œโ”€โ”€ product-gallery
โ”‚ โ”‚ โ”œโ”€โ”€ product-gallery.liquid
โ”‚ โ”‚ โ”œโ”€โ”€ product-gallery.snippet.scss
โ”‚ โ”‚ โ””โ”€โ”€ product-gallery.snippet.ts
โ”‚ โ””โ”€โ”€ product-recommendations
โ”‚ โ”œโ”€โ”€ product-recommendations.liquid
โ”‚ โ”œโ”€โ”€ product-recommendations.snippet.scss
โ”‚ โ””โ”€โ”€ product-recommendations.snippet.ts
โ””โ”€โ”€ shared
โ”œโ”€โ”€ message
โ”‚ โ”œโ”€โ”€ message-body
โ”‚ โ”‚ โ”œโ”€โ”€ message-body.liquid
โ”‚ โ”‚ โ”œโ”€โ”€ message-body.scss
โ”‚ โ”‚ โ””โ”€โ”€ message-body.ts
โ”‚ โ”œโ”€โ”€ message-box
โ”‚ โ”‚ โ”œโ”€โ”€ message-box.liquid
โ”‚ โ”‚ โ”œโ”€โ”€ message-box-section
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ message-box-section.liquid
โ”‚ โ”‚ โ”‚ โ”œโ”€โ”€ message-box-section.snippet.scss
โ”‚ โ”‚ โ”‚ โ””โ”€โ”€ message-box-section.snippet.ts
โ”‚ โ”‚ โ”œโ”€โ”€ message-box.snippet.scss
โ”‚ โ”‚ โ””โ”€โ”€ message-box.snippet.ts
โ”‚ โ”œโ”€โ”€ message.liquid
โ”‚ โ”œโ”€โ”€ message.snippet.scss
โ”‚ โ””โ”€โ”€ message.snippet.ts
โ”œโ”€โ”€ promo-banner
โ”‚ โ”œโ”€โ”€ promo-banner.liquid
โ”‚ โ”œโ”€โ”€ promo-banner.snippet.scss
โ”‚ โ””โ”€โ”€ promo-banner.snippet.ts
โ””โ”€โ”€ sidebar-cart
โ”œโ”€โ”€ sidebar-cart.liquid
โ”œโ”€โ”€ sidebar-cart.snippet.scss
โ””โ”€โ”€ sidebar-cart.snippet.ts

You can leverage from our built-in Code Generators to scaffold the theme structure you desire. The code generators will take care of verifying that no duplicated blocks will be created even if you try to do it in different subfolders.

important

Do not forget that a theme block name should be unique in it's block type. You can perfectly have a snippet and a section both called message-box at the same time.