Install a Drupal theme from composer

Submitted by admin on Sun, 06/13/2021 - 18:20

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" : "" }, { "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.

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.