Child-Theme
A child theme is the basis for any programming that affects the frontend.
Last updated
A child theme is the basis for any programming that affects the frontend.
Last updated
In this article, I'll explain how to create clean child themes in Shopware 6. You will learn how to set the inheritance structure correctly and thus leave the main theme untouched.
This allows you to do your own programming and the main theme remains update-compatible without exception. This article is primarily or exclusively aimed at developers.
If you want to find out more about theme duplicates, I recommend my article on this. Otherwise, you can ignore this note.
I have spared no expense or effort to provide you with a free template to download.
The template can be used almost universally and has, for example, its own JS plugin and the "Lato" font integrated for illustration purposes. This template or the child theme itself is an independent theme and must therefore be edited as such.
Github Repo / Download |
---|
In the template, you can see the configuration for inheritance in the file
src > Resources > theme.json
You probably know how to change the meta information and the namespace of the child theme. But in this file you will find the value @ParentThemeNamespace. You must exchange this value with the value of the theme to be overwritten for the inheritance to take effect.
You can find the namespace to be replaced in the composer.json file of the main theme.
For my Tronic theme, for example, it would be the namespace @RHWebTronic
Child theme cannot be assigned to the sales channel?
This error usually occurs if an SCSS variable of the main theme could not be found. In this case, you should run the command bin/console theme:refresh
in the console, or uninstall and reinstall the child theme.
in all other cases, please check whether the theme.json file is correct and the theme has been compiled correctly.
Before you get started, you should take the following precautions! These are not necessary for you to be able to program. They are just a few pieces of meta information for your CI.
Change Namespaces There are a few issues here, e.g. the folder name, the class, the composer.json file, etc.
Customize supplied Javascript The child theme comes with a sample Javascipt plugin in the folder.
Exchange preview and icon You will find the preview image in the src > Resources > app folder. And in the src > Resources > config folder you will find the app icon.
Customize views In the src > Resources > views folder you will find an example of base.html.twig.
Change Fonts The child theme integrates the "Lato" font to show you an example of how to implement your own fonts. The font is integrated in the assets folder of the theme and in the respective .scss.
I will explain how to include your own fonts in another article.
Now you're ready to go! Your child theme is fully configured and the main theme remains update-compatible. The child theme automatically inherits new settings from the main theme.