Adding documentation about cascading themes

This commit is contained in:
Guy Marriott 2019-05-31 16:31:08 +12:00
parent 2eb04ffa78
commit 9feef185dc
No known key found for this signature in database
GPG Key ID: A80F9ACCB86D3DA7
4 changed files with 59 additions and 9 deletions

View File

@ -96,7 +96,55 @@ In some Browsers the SubsiteID is visible if you hover over the "Edit" link in t
### Subsite-specific themes ### Subsite-specific themes
Download a second theme from http://www.silverstripe.com/themes/ and put it in your themes folder. Open admin/subsites?flush=1 and select one of your subsites from the menu on the bottom-left. You should see a Theme dropdown in the subsite details, and it should list both your original theme and the new theme. Select the new theme in the dropdown. Now, this subsite will use a different theme from the main site. Download a second theme from http://www.silverstripe.com/themes/ and put it in your themes folder. Open
admin/subsites?flush=1 and select one of your subsites from the menu on the bottom-left. You should see a
Theme dropdown in the subsite details, and it should list both your original theme and the new theme. Select the new
theme in the dropdown. Now, this subsite will use a different theme from the main site.
#### Cascading themes
In SilverStripe 4 themes will resolve theme files by looking through a list of themes (see the documentation on
[creating your own theme](https://docs.silverstripe.org/en/4/developer_guides/templates/themes/#developing-your-own-theme)).
Subsites will inherit this configuration for the order of themes. Choosing a theme for a Subsite will set the list of
themes to that chosen theme, and all themes that are defined below the chosen theme in priority. For example, with a
theme configuration as follows:
```yaml
SilverStripe\View\SSViewer:
themes:
- '$public'
- 'my-theme'
- 'watea'
- 'starter'
- '$default'
```
Choosing `watea` in your Subsite will create a cascading config as follows:
```yaml
themes:
- 'watea'
- '$public'
- 'starter'
- '$default'
```
You may also completely define your own cascading theme lists for CMS users to choose as theme options for their
subsite:
```yaml
SilverStripe\Subsites\Service\ThemeResolver:
theme_options:
normal:
- '$public'
- 'watea'
- 'starter'
- '$default'
special:
- 'my-theme'
- 'starter'
- '$default'
```
### Limit available themes for a subsite ### Limit available themes for a subsite

View File

@ -59,8 +59,11 @@ class ThemeResolver
$index = array_search($siteTheme, $themes); $index = array_search($siteTheme, $themes);
if ($index > 0) { if ($index > 0) {
// 4.0 didn't have support for themes in the public webroot
$publicConstantDefined = defined('SSViewer::PUBLIC_THEME');
// Check if the default is public themes // Check if the default is public themes
$publicDefault = $themes[0] === SSViewer::PUBLIC_THEME; $publicDefault = $publicConstantDefined && $themes[0] === SSViewer::PUBLIC_THEME;
// Take only those that appear after theme chosen (non-inclusive) // Take only those that appear after theme chosen (non-inclusive)
$themes = array_slice($themes, $index + 1); $themes = array_slice($themes, $index + 1);

View File

@ -11,7 +11,7 @@ use SilverStripe\View\SSViewer;
class ThemeResolverTest extends SapphireTest class ThemeResolverTest extends SapphireTest
{ {
protected $themeList = [ protected $themeList = [
SSViewer::PUBLIC_THEME, '$public',
'custom', 'custom',
'main', 'main',
'backup', 'backup',
@ -55,7 +55,7 @@ class ThemeResolverTest extends SapphireTest
$expected = [ $expected = [
'main', // 'main' is moved to the top 'main', // 'main' is moved to the top
SSViewer::PUBLIC_THEME, // $public is preserved '$public', // $public is preserved
// Anything above 'main' is removed // Anything above 'main' is removed
'backup', 'backup',
SSViewer::DEFAULT_THEME, SSViewer::DEFAULT_THEME,
@ -87,7 +87,7 @@ class ThemeResolverTest extends SapphireTest
['test' => $expected = [ ['test' => $expected = [
'subsite', 'subsite',
'backup', 'backup',
SSViewer::PUBLIC_THEME, '$public',
SSViewer::DEFAULT_THEME, SSViewer::DEFAULT_THEME,
]], ]],
'test', 'test',
@ -104,7 +104,7 @@ class ThemeResolverTest extends SapphireTest
'bee' => $expected = [ 'bee' => $expected = [
'subsite', 'subsite',
'backup', 'backup',
SSViewer::PUBLIC_THEME, '$public',
SSViewer::DEFAULT_THEME, SSViewer::DEFAULT_THEME,
], ],
'sea' => [ 'sea' => [
@ -121,7 +121,7 @@ class ThemeResolverTest extends SapphireTest
['main' => $expected = [ ['main' => $expected = [
'subsite', 'subsite',
'backup', 'backup',
SSViewer::PUBLIC_THEME, '$public',
SSViewer::DEFAULT_THEME, SSViewer::DEFAULT_THEME,
]], ]],
'main', 'main',
@ -132,7 +132,7 @@ class ThemeResolverTest extends SapphireTest
['test' => [ ['test' => [
'subsite', 'subsite',
'backup', 'backup',
SSViewer::PUBLIC_THEME, '$public',
SSViewer::DEFAULT_THEME, SSViewer::DEFAULT_THEME,
]], ]],
'other', 'other',

View File

@ -417,7 +417,6 @@ class SiteTreeSubsitesTest extends BaseSubsiteTest
Subsite::changeSubsite($subsitePage->SubsiteID); Subsite::changeSubsite($subsitePage->SubsiteID);
$controller = ModelAsController::controller_for($subsitePage); $controller = ModelAsController::controller_for($subsitePage);
SiteTree::singleton()->extend('contentcontrollerInit', $controller); SiteTree::singleton()->extend('contentcontrollerInit', $controller);
} }
public function provideAlternateAbsoluteLink() public function provideAlternateAbsoluteLink()