Create a Child Theme


#1

Silverstripe Version: 4.3.1

Is it possible to create a child theme from a parent theme like “simple”? Like it is possible in Wordpress.

Definition of a child theme:
A child theme is a theme that inherits the functionality and styling of another theme, called the parent theme. Child themes are the recommended way of modifying an existing theme.

I searched on Google but didn’t find any information about creating a child theme for SilverStripe.


#2

As of SS4 you can, the key is that you have to define the theme priority in your yml config.

The main templating docs should be here:

https://docs.silverstripe.org/en/4/developer_guides/templates/template_inheritance/

In particular have a look at:

https://docs.silverstripe.org/en/4/developer_guides/templates/template_inheritance/#cascading-themes


#3

Thanks, I read the docs and I think I got it working.

  1. Copied “simple” theme renamed folder to “simple2”, modified composer.json
  2. Deleted all files from “simple2” except layout.css
  3. Changed background-color from header
  4. Modified theme.yml order:
---
Name: mytheme
---
SilverStripe\View\SSViewer:
  themes:
    - 'simple2'
    - 'simple'
    - '$default'
    - '$public'

Now it seems the simple2 theme is loaded and falls back to simple if files not exist.
Is this the right way?


#4

Looks right to me, SS will keep stepping through the list until it finds the file it needs, theoretically you can add as many themes as you want (though I haven’t tried more than 3).

One thing of note, I don’t think you need to worry about composer.json for your custom theme, I think SSViewer simply looks inside the the “themes” folder for any folders matching the list of themes you provide to it (though I could be wrong).


#7

Alright, it’s still working fine :slight_smile: Thanks guys!


#5

You probably still do if you want to expose resources from the theme.


#6

Ah yes, public folder! You probably do want to keep it then :slight_smile: