Setting up your local environment
Now that you intend to building a theme for PrestaShop, you are better off keeping all your development work on your machine. The main advantage is that it makes it possible for you to entirely bypass the process of uploading your files on your online server in order to test your changes. Another advantage is that a local test environment enables you to test code without the risk of breaking your production store. Having a local environment is the essential first step in the path of web development.
The following content assumes you’re a developer and you want to create a theme or a module.
Then, open a command line on your (empty) working directory, then:
git clone https://github.com/PrestaShop/PrestaShop.git
Using git you can choose your PrestaShop version:
git checkout 188.8.131.52. Also we would warn you to test your final result with a zip release, just for safety (since vendor version might be slightly different).
If you haven’t done it yet, we strongly recommend you to read our article Set Up Your Git For Contributing
Building your .gitignore file
A gitignore file is a must-have for any Git-versioned project, as it specifies intentionally untracked files that Git should ignore.
What to ignore
Generally, you shouldn’t version the following types of files:
- Temporary files (such as cache files)
- Generated files (such as minified CSS or retrieved XML files)
- Files with credentials or personal information (such as
- OS and IDE-related files (such as .DS_Store or .idea/)
We suggest that you build your own using http://gitignore.io.
If you are building a full project for a client, you can read our article on building a gitignore for PrestaShop.
Create your theme from the Starter Theme
When you want to create a theme, the best way is to use the Starte rTheme as a base theme.
Create a new folder under
themes/ then download the Starter Theme and copy its files in your new folder.
Create your theme.yml file
First of all, you need to rename
config/theme.yml and edit it according to your theme’s name.
Once it’ done you’ll be able to select your theme in your back office.
PrestaShop 1.7 introduces a new way for designers to create their theme from scratch: the Starter Theme. The default theme for PS 1.7 is based on the Starter Theme.
This means that a lot of themes are tied to the default theme’s technical choices, because this way of working makes it hard to make your own choices. For instance, since the default theme uses Bootstrap, it’s hard to use Foundation.
By using the Starter Theme as the foundation for your custom theme, everything is ready for you, you just have to create upon it.
Downloading the Starter Theme
The Starter Theme is available on GitHub: https://github.com/PrestaShop/StarterTheme
If you download the Starter Theme and select it as the theme for your store, you will see minimalist theme with an overly simplistic (ugly?) style. This is only for development purpose. You should NOT use the Starter Theme as is, and you should NOT use its default CSS rules nor include them in your theme: please delete all files inside _dev/css.
Here is a:
The jQuery v2 library is loaded by the core.js file.
Please note that if you want to sell your theme on the PrestaShop Addons marketplace, there are some specific requirements. For instance, Addons-distributed themes MUST use Bootstrap 4.
Modify. Don’t override.
When you want to create a new theme, copy and paste all files from the Starter Theme inside your empty theme directory. Then you start modifying it, and building your own theme.
Do not use it as a parent theme, you will only run into trouble and waste your time.
Once you removed all style in
_dev/css, your theme should like this:
A PrestaShop theme is a set of files which you can edit in order to change the look of your online shop.
Here are a few important tidbits:
- All themes have their files located in the /themes folder, at the root of PrestaShop’s folder.
- Each theme has its own sub-folder, in the main themes folder.
- Each theme has a preview.png image file in its folder, enabling the shop-owner to see what the theme looks like directly from the back office, and select the theme appropriately.
The best way to learn how to create a theme for PrestaShop 1.7 is to dive into the Starter Theme.
Here is its organization, which is explained further below.
The folders are used this way:
|assets||Contains the production assets, compiled by Webpack from the _dev files.|
|config||Contains configuration file. By default, it only has the theme.yml file.|
|module||Contains either theme-specific modules, or the theme’s version of native modules’ template files. For instance, the |
|plugins||Your custom smarty plugins|
|templates||Contains the template files themselves (.tpl), mostly in contextual sub-folders (catalog, checkout, cms, etc.). The _partials folder contains “partial templates”, which means parts that can used by / included into several templates: header.tpl, breadcrumb.tpl, footer.tpl, etc. This prevents redundant code blocks, and makes themes easier to maintain.|
Required templates and libraries
When you install/enable a theme, PrestaShop checks if the theme is valid: it looks for the theme.yml file (and checks its content), its declared compatibility, and the existence of some files.
There is a list of files that need to exists, even if they’re empty. Please see dedicated documentation to know what makes a theme valid.
It could be that you’ve built some sort of groundbreaking theme and it doesn’t exactly work like the Starter Theme does. For instance, if you don’t have a product page, then you don’t need the product.tpl file. In that case, you just have to create an empty product.tpl file. Be nice to the next developer and add a comment indicating where the code related to products can be found ;)
jQuery v2.1 is loaded by the core (bundled in
core.js) file, but no other libraries, since the idea is that the Starter Theme should not be opinionated.
Read more about assets management.
The theme’s theme.yml file defines all of the theme’s configuration and meta information, such as its version number, layouts, compatibility range, hook configuration, etc.
The theme’s name MUST match its directory name. For instance, if the theme is named “My Awesome Theme” and its ‘name’ value is set to “my-awesome-theme”, then the folder MUST be /my-awesome-theme .
Users will be able to choose the layout for each page from the theme’s settings page. Layouts are automatically parsed from the theme’s /templates/layouts folder, so this configuration key is optional, but it allows designers to provide some more user-friendly info than just a filename.
You can have the theme change the configuration of PrestaShop when the theme is enabled.
You can have the theme enable or disable modules when the theme is enabled.
Since PrestaShop 184.108.40.206, theme activation can also reset modules:
You can have the theme create hooks and attach modules to custom and existing hooks when the theme is enabled.
All the settings below can be changed through an interface in the theme’s back office interface, and only depend on the theme/shop combination.
When the theme.yml file is parsed by PrestaShop, the ‘theme_settings’ configuration key is copied to a file named settings_n.yml, where ‘n’ is the id of the shop where the theme is installed (settings_123456.yml, for instance).
When the configuration is changed through the back office interface, only the settings_n.yml file is updated - the theme.yml file remains unchanged.
When making a theme you may want to add features with custom modules. It’s important that these modules are installed with your theme. These modules should be declared as dependencies so you’re sure prestashop will export them when creating your theme zipball.
So far themes only have modules dependencies.