Install a Drupal theme from composer

By Lars Nielsen ·

Composer is a way to organize different parts of a project in code. 

When building a website you can have a project which is your website which imports other components such as modules and themes.

In your website project you should add a composer.json file which describes the dependencies of your project. Start by defining a composer.json description i your theme base-folder.

composer create-project drupal/recommended-project YOUR_DIR<

Now you have a composer.json file which describes a Drupal project.

Add path to repositories part of composer.json

"repositories" : [{ "type" : "composer", "url" : "https://packages.drupal.org/8" }, { "type" : "path", "url" : "../themes/slagter" } ],

Another important step is to change the minimum-stability entry so you can use a local dev theme.

"minimum-stability" : "dev",

Now issue the following command to import the theme into the drupal project.

composer require lars/slagter-theme

When you are ready to publish your site to production you should change the local path to a reference to a git repository. And you should change the "minimum-stability" back to "stable". This last change will require that you have a tagged release on the chosen git repository.

Related reading

Filed under

Leave a comment

Comments are reviewed before they appear.

Basic HTML allowed: links, emphasis, code and lists. Web addresses become links automatically.