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.
#
AssetsAll the assets content will be placed inside this directory. You can organize your assets using as many subdirectories as you want (can be nested).
The theme build output will flatten all the files into a single assets
directory. The above example will generate the following output:
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 assetsAs 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:
Then, in your liquid code:
#
CoreThe 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.
#
EnvironmentsAll the TypeScript environment files will be placed in this directory.
tip
Learn more about working with environments in the Environments Guide.
#
ThemeThe src/theme
directory contains all the theme blocks separated in their respective subdirectory
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:
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.