mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
Adding documentation about cascading themes
This commit is contained in:
parent
2eb04ffa78
commit
9feef185dc
50
README.md
50
README.md
@ -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
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
@ -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',
|
||||||
|
@ -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()
|
||||||
|
Loading…
Reference in New Issue
Block a user