A Drupal 8 theme template that works with SASS, Bower, Gulp and any Drupal 8 base theme you want to use. This template also has a self-update feature built in and you should never have to copy/paste anything when setting up a custom theme for a Drupal project in the future.
By default, this template uses Bartik as the base theme and you can start using it in an existing Drupal project by calling:
This will add this template as a dependency to your composer.json file and create a custom theme named
mytheme with all the settings requiered to get started immediately.
Define the theme name¶
To define a specific theme name you should simply add the following section to your '.lakedrops.yml':
It is best practice to add this configuration into the composer.json before you install the theme itself, otherwise you'll end up with two custom themes, one with the default name and a second one with your own theme name.
Define and configure the base theme¶
To use a different base theme than Bartik you can add the following configuration to your composer.json:
1 2 3 4 5 6 7 8
|name||bartik||The Drupal project name of the base theme.|
|package||The composer package name with namespace and package name so that Composer is able to find the package in the current installation for additional resources like starterkit. This parameter is required if you want to use any of the following settings and you have to make sure that this package is included as a requirement for your project.|
|starterkit||If the base theme comes with a starterkit you can specify the relative path within that project where to find it.|
|sasspath||The created custom theme is always based on a subdirectory called
|import||||If the starterkit comes with basic files that you should import, then you can provide a list of names that will then be imported automatically.|
Note: if you're using bootstrap as your base theme, you will also have to add the bower assets for the Bootstrap library which is explained below. The same may apply for other base themes, you should always find their requirements in their own documentation. Feel free to notify us about configurations on other base themes and we'll be adding that into the documentation here as well.
Adding bower assets¶
Either a base theme or your own theme development style may require some libraries that are provided by Bower. To add one or more Bower assets to your theme, simply add a section like this to your composer.json:
1 2 3 4 5 6 7 8 9 10 11 12 13
In the above example
bootstrap-sass in the package name from the bower package repository and it contains a dictionary of values with these options:
|name||The name how to identify this asset in your own theme.|
|version||This value is optional and defaults to the
|fonts||A dictionary containing the source directory where to find the fonts of that package. Those fonts will be copied over into your custom theme.|
|sass||A dictionary containing the source directory where to find the sass file of that package and a list of sass files that will be imported by the sass compiler when required. Those sass file will not be copied to your custom theme, because they will only be required for compilation but not to deliver those files to the browser of your website visitors.|
A bower.json file will be created dynamically when composer is executed and bower will be executed automatically to install and update all required assets locally in your theme.
Add bower assets globally¶
The previous chapter describes how to add bower assets to your custom theme and without doing anything else, they will be added locally to your theme by using bower to install and update them.
If you either want to avoid that overhead of using Bower or if any of these assets will be used by multiple projects, then you could install them globally in the vendor directory of your Drupal project. This will be done by composer if you add the following settings to your composer.json in addition to the settings in the previous chapter:
1 2 3 4 5 6 7 8 9 10 11
Your custom theme will then just use the assets from the vendor directory rather than keeping them in a
bower_components subdirectory of the theme. But you still need the
bower_assets settings in the extra section as described above.
Other Bower Assets¶
A short list of bower assets that might be interesting to add them to your theme:
1 2 3 4 5
1 2 3 4 5 6 7 8 9 10 11 12
1 2 3 4 5
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5
1 2 3 4 5 6 7 8 9 10
For the animate package you have an additional list called
modules which contains a list of animation modules that you want to enable for your custom theme.
Add optional scripts¶
The custom theme will be updated when ever you either run
composer install or
composer update on your project. However, sometime you may only want to update the theme without running composer on the full project and you can achieve that by adding some custom scripts to your composer.json file:
1 2 3 4 5 6 7 8
You don't need them all, just add those that make sense to your development workflow. To run any of those scripts simply call
composer drupal-theme-update which will then run that script.
The available scripts in this package are:
|init||Create or update the theme with all its files and settings. Do not overwrite any custom files and finally run
composer update in the root of your project and the latest version of this plugin will be updated and the changed files will then be updated in your custom theme. No worries, the files that you edited in your theme and that are not core to this plugin, won't be overwritten, so you keep your own work easily.
At the end of the update,
The sass compiler also knows a development and a production mode. It uses development mode by default and production mode when composer is run with the
--no-dev command line argument, which is usually the case in production environments.
Go to your theme's directory and call
gulp once to run all of the available pre-processing. This is the equivalent of calling
If Gulp is not installed globally then you need to call
node_modules/.bin/gulp in all examples of this chapter.
Gulp by default will run the tasks
css which are described in detail below.
gulp fonts will copy all fonts from all configured bower assets into the fonts subdirectory of your custom theme.
gulp css will compile your sass files into css once. When adding the argument
--env production then the output will be optimized for production environments, otherwise the output will be optimized for development.
gulp watch will start a process that monitors your sass directory and automatically calls the css compilation when ever one or more files have changed.
This template is embedded in our D8 Project Template and looking into the composer.json there shows you all the options in action.