Grav is a tremendous CMS. It is very easy to generate content with it, many times a basic installation accompanied by the Admin plugin and a good theme is all we need to make a website and publish content. At the time of this publication, there are 114 themes available for free in the Download section of the official Grav website. Completely ready-to-install themes to make our website look great.
But what happens when we need to make some kind of modification on the theme itself? We could make our theme from scratch, a private theme to which we can make all the modifications we want; however most of the time that is not an option. On the other hand, if we download and install a theme and modify it directly, then we will lose our changes when the theme is updated to a new version. This is the ideal situation to inherit from a base theme!
Let's create an inheritance from the default Grav theme: Quark. We are going to do it using the powerful Grav CLI. Depending on where you have your Grav installation hosted you may need remote access via SSH to use the CLI, but that is beyond the scope of this article. You should take a look at the documentation of the Web Hosting service provider to find out how to establish an SSH connection with your server.
So, let's get our hands a little dirty…
How to inherit a base theme
To get started we need to install the DevTools plugin, so from the root folder of our Grav installation we are going to run the following command:
$ bin/gpm install devtools
At the end of the installation, if no error occurred, we should see something similar to the following:
We can also install the DevTools plugin manually, for this we must do the following:
- Enter the Admin of our Grav installation and go to the Plugins section from the main menu on the left side of the screen.
- Click on the Add button located at the top right.
- Find the DevTools plugin and click the Install button.
Then, from the root of our Grav installation, we will execute the following command:
$ bin/plugin devtools new-theme
At the beginning of the process we will be asked several questions about our new theme, namely:
- Enter Theme Name (we will type the name we want for our new theme).
- Enter Theme Description (we will type a description on our new theme).
- Enter Developer Name (we will type our name or that of our company if we wish).
- Enter GitHub ID (our GitHub ID, we can leave it blank).
- Enter Developer Email (we will type our email address).
- Please choose an option:
When selecting an option we will use the keyboard arrows until the inheritance option is selected and we will press the ENTER/RETURN key. We could type in the word inheritance directly on this prompt as well.
Then we will be asked what is the theme that we want to inherit. The only thing we have to do in this part is type the number that appears to the left of the name of the theme or themes that we have installed.
In this case, there are two themes installed: Mediator and Quark. Since we want to inherit from Quark we will type the number 1 and press the ENTER/RETURN key.
That way we'll be ready, we will see a confirmation like the following:
Now we just have to go into our Grav Admin and activate the newly created theme, or edit the system.yaml file located in the /user/config/ folder of our Grav installation to change the theme we want to use.
Additionally, we can inherit a theme manually by copying the base theme files to a new folder inside /user/themes/. To do this, we recommend following Grav's excellent documentation on How to manually inherit themes in Grav CMS.
Until next time.