|
| 1 | +--- |
| 2 | +title: "Theming" |
| 3 | +linkTitle: "Theming" |
| 4 | +weight: 15 |
| 5 | +type: "landing" |
| 6 | +draft: false |
| 7 | +translated: false |
| 8 | +resources: |
| 9 | + - src: "**.{png,jpg}" |
| 10 | + title: "Image #:counter" |
| 11 | + params: |
| 12 | + byline: "Image: Drupal / CC-BY-CA" |
| 13 | +categories: |
| 14 | +- wxt |
| 15 | +tags: |
| 16 | +- theming |
| 17 | +--- |
| 18 | + |
| 19 | +Largely when doing any theme related work with **[Drupal WxT][wxt]** this almost always should be done in a sub-theme. |
| 20 | + |
| 21 | +For more on creating sub-themes please consult the official documentation: |
| 22 | + |
| 23 | +- **[Creating sub-themes][sub-themes]** |
| 24 | + |
| 25 | +To assist with sub-theme creation **[WxT Bootstrap][wxt_bootstrap]** provides an example starterkit that should be of benefit. |
| 26 | + |
| 27 | +> **Note**: Sub-themes are just like any other theme except they inherit the parent theme's resources. |
| 28 | +
|
| 29 | +## Sub Theme Configuration |
| 30 | + |
| 31 | +a) Replace every instance of `THEMENAME` with your chosen machine name often of the pattern `<prefix>_bootstrap`. |
| 32 | + |
| 33 | +b) Enable your new sub-theme preferably via **[drush][drush]**: |
| 34 | + |
| 35 | +```sh |
| 36 | +drush en `<prefix>_bootstrap` |
| 37 | +drush cc css-js |
| 38 | +``` |
| 39 | + |
| 40 | +c) Point to your new sub theme for **[WxT Library][wxt_library]** to properly load assets under **Themes Visibility** on the `/admin/config/wxt/wxt_library` page. |
| 41 | + |
| 42 | +## Notes |
| 43 | + |
| 44 | +### Inheriting Block Templates |
| 45 | + |
| 46 | +If the theme you are extending has custom block templates these won't be immediately inherited because a sub-theme creates copies of all the blocks in the parent theme and renames them with the sub-theme's name as a prefix. Twig block templates are derived from the block's name, so this breaks the link between these templates and their block. |
| 47 | + |
| 48 | +To fix this problem it requires a hook in the sub-theme by adding the following code snippet to the `THEMENAME.theme` file: |
| 49 | + |
| 50 | +### Programmatic Logic |
| 51 | + |
| 52 | +The following provides an example of how you can configure your sub theme to be installed as the default on a module install: |
| 53 | + |
| 54 | +```php |
| 55 | +/** |
| 56 | + * Implements hook_modules_installed(). |
| 57 | + */ |
| 58 | +function MODULENAME_modules_installed($modules) { |
| 59 | + if (in_array('wxt', $modules)) { |
| 60 | + \Drupal::configFactory() |
| 61 | + ->getEditable('system.theme') |
| 62 | + ->set('default', 'THEMENAME') |
| 63 | + ->set('admin', 'claro') |
| 64 | + ->save(TRUE); |
| 65 | + } |
| 66 | + } |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +The following provides an example of how you can configure `wxt_library` to use your sub theme by creating a `config/install/wxt_library.settings.yml` file with the following contents: |
| 71 | + |
| 72 | +```yaml |
| 73 | +url: |
| 74 | + visibility: 0 |
| 75 | + pages: |
| 76 | + - 'admin*' |
| 77 | + - 'imagebrowser*' |
| 78 | + - 'img_assist*' |
| 79 | + - 'imce*' |
| 80 | + - 'node/add/*' |
| 81 | + - 'node/*/edit' |
| 82 | + - 'print/*' |
| 83 | + - 'printpdf/*' |
| 84 | + - 'system/ajax' |
| 85 | + - 'system/ajax/*' |
| 86 | +theme: |
| 87 | + visibility: 1 |
| 88 | + themes: |
| 89 | + THEMENAME: THEMENAME |
| 90 | + wxt_bootstrap: wxt_bootstrap |
| 91 | +minimized: |
| 92 | + options: 1 |
| 93 | +files: |
| 94 | + types: |
| 95 | + css: css |
| 96 | + js: js |
| 97 | +wxt: |
| 98 | + theme: theme-gcweb |
| 99 | +``` |
| 100 | +
|
| 101 | +<!-- Links Referenced --> |
| 102 | +
|
| 103 | +[drush]: https://www.drush.org/latest/ |
| 104 | +[sub-themes]: https://www.drupal.org/docs/theming-drupal/creating-sub-themes |
| 105 | +[wxt]: https://github.com/drupalwxt/wxt |
| 106 | +[wxt_bootstrap]: https://www.drupal.org/project/wxt_bootstrap |
| 107 | +[wxt_library]: https://www.drupal.org/project/wxt_library |
0 commit comments