I have a Drupal 8 Multisite setup with the following Folder structure:

  • themes
    • custom_theme
      • main_custom_theme
  • sites
    • site1
      • themes
        • subtheme1
    • site 2

So I want both sites to use main_custom_theme, but site1 needs to override one template (page.html.twig) with subtheme1. subtheme1 folder contains a subtheme1.info.yml as follows:

name: subtheme1
description: "Custom sub-theme"
core: 8.x
type: theme
base theme: main_custom_theme

I rebuilt all caches (Backend and drush cr, but drush cr might not clean caches of subsites?) but cannot select the new subtheme in Backend of site1. What am I missing?

This is the Twig Debug output after using leymannx answer, subsites path is "leistungen"

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'page' -->
   * page--leistungen.html.twig
   * page--node--560.html.twig
   * page--node--%.html.twig
   * page--node--article.html.twig
   * page--node.html.twig
   x page.html.twig
<!-- BEGIN OUTPUT from 'themes/custom/my_custom_theme/templates/main/page.html.twig' -->

I have a question that builds on this one... I published it appearently with a different user, without wanting to. Still new to not only reading stackexchange :)

If I try to do the same for the node of my content type, which is using a template named node--CONTENTTYPENAME.html.twig at the moment, I can insert a name suggestion node--NAMEOFSUBSITE.html.twig, which will then be used for ALL nodes. I'd like to insert a suggestion such as node--CONTENTYPENAME--NAMEOFSUBSITE.html.twig, for only this one nodetype.

How can I do that?

Thanx in advance!!

  • So inside themes/custom/my_custom_theme/templates/main there is a page--leistungen.html.twig? – leymannx May 30 '18 at 11:36
  • It is inside themes/custom/my_custom_theme/templates/main . That's also where the used page.html.twig is located. – Loxx May 30 '18 at 11:56
  • And did you try to put it into themes/custom/my_custom_theme/templates as well? Really strange then. I'd say it's caching. But you said you already flushed all Drupal caches. – leymannx May 30 '18 at 11:59
  • Yes I did, on all subsites in Backend, with drush cr and drush -l leistungen cache:rebuild I think it's caching, too. But wondering, why other template changes are recognized? It's weird. – Loxx May 30 '18 at 12:12
  • Gosh, we must miss something. There must be a typo or something. The suggestion is there, so it MUST pick up the template. Why wouldn't it pick up the template? ( •́ ⍨ •̀) – leymannx May 30 '18 at 12:21

In Drupal 8 you are supposed to organize your themes and multi-site instances like in the following structure. I only highlight the relevant folders.

  |  |__contrib
  |  |  |__devel
  |  |  |__views
  |  |__custom
  |     |__my_module_abc
  |     |__my_module_xyz
  |  |__default
  |  |  |__settings.php
  |  |__site1
  |  |  |__settings.php
  |  |__site2
  |     |__settings.php
     |  |__bootstrap

So, if you want to create a sub-theme of a custom theme, you also have to place it inside docroot/themes/custom. Then it will appear in your back-end where you can enable it.

But what I would recommend instead of adding another sub-theme, is to simply add a template suggestion based on the multi-site instance name via hook_theme_suggestions_HOOK_alter. By that you can move on with only one custom theme (which is much easier to maintain in the end), and inside its MYTHEME.theme file you'll switch the page template for your certain multi-site instance like following.

 * Implements hook_theme_suggestions_HOOK_alter().
function MYTHEME_theme_suggestions_page_alter(array &$suggestions, array $variables) {

  $site_path = \Drupal::service('site.path');
  $site_path = explode('/', $site_path);
  $site_name = $site_path[1];

  $suggestions[] = 'page__' . $site_name;

Now you simply can place page--site1.html.twig in your theme's template folder and site1 will take this page template instead the default page.html.twig. (Source)

Tried it on a fresh D8 with Twig debugging enabled and it works just fine.

<!-- THEME DEBUG -->
<!-- THEME HOOK: 'page' -->
   x page--site1.html.twig
   * page--front.html.twig
   * page--node--1.html.twig
   * page--node--%.html.twig
   * page--node.html.twig
   * page.html.twig
<!-- BEGIN OUTPUT from 'themes/custom/my-custom-subtheme/templates/page--site1.html.twig' -->

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.