Themes
This guide is an entry point for working with themes
Concept
To shadow (override) - to create a file which will be used in the application instead of some other file. You can shadow files of any extension and any parent theme.
Set up a parent theme
First of all, you will need to create a parent theme. A parent theme is a project that will be used as a base for a child theme, which will modify some of its functionality.
Let's have a parent theme configured as follows.
And let's put the following file there. This file we are going to override a bit later.
Also, let's use the functionality from above in that parent theme!
The this parent theme will output the following logging. This will change when we introduce a child theme!
Set up a child theme
Then, let's create a child theme. A child theme will extend the parent theme's functionality and modify it.
We will configure the child theme as follows. We set the parent theme to the theme we have created above. It is important to install the parent theme into this project!
Shadow
In the child theme, we will create a file with the same path as above, and modify some functionality.
We are not going to create any additional files in our child theme. We wanted to change a single thing and we did it!
Ensure all exports
Remember to re-export all of the initial file's exports, which you are not overriding. This way we ensure nothing will get lost after the modifications. This is done to the SOME_VALUE
in the example above.
If you forget to re-export something, the application will lose any access to these values.
Review project structure
See the full project structure below.
Demonstration
Let's now see what happens when we run the project. We are going to see the logging from the run
method, which was kept intact. But the value of this logging is absolutely different!
As you see, during the project build resolution of all of the files fell back to the parent theme, except one file we have overridden. Our override changed the part of functionality we were willing to change and now the theme works differently.
How cool is that! Find out more in the guide above.
Last updated