3

I have several Drupal 9 sites on multi-site setup. currently all these sub sites use one theme placed in /themes/MyTheme folder.

now i need to theme few nodes on site A and site B and this is only difference between all sites. if i use page--node--x.html.twig convention to change layout of node x on site A, it changes layout of node x on all sites.

what is easiest way to apply page--node--x.html.twig only to site A but not site B?

is it possible to have theme on themes/MyTheme/ folder but copy only page--node--x.html.twig to sites/siteA/themes/custom folder to overwrite this layout only for site A?

2
  • 2
    You can’t just copy the template file, you’ll need to create a sub theme. But once you’ve done that, yes it’s as simple as copying the single template file over Commented Jan 29, 2022 at 13:44
  • Thanks @Clive. is the sub theme the only way? is it possible to inject or apply these twig file for specified site Programmatically via mytheme.theme file? Commented Jan 29, 2022 at 13:50

1 Answer 1

5

I once had a question on how to get current multi-site instance name. You can use the accepted answer's code to add another template suggestion based on the name then:

/** * Implements hook_theme_suggestions_HOOK_alter(). */ function MYTHEME_theme_suggestions_node_alter(array &$suggestions, array $variables) { $site_path = \Drupal\Core\DrupalKernel::findSitePath(\Drupal::request()); $site_path = explode('/', $site_path); $site_name = $site_path[1]; $site_specific_suggestions = []; foreach ($suggestions as $suggestion) { $site_specific_suggestions[] = $suggestion . '__site_' . $site_name; } $suggestions = array_merge($suggestions, $site_specific_suggestions); } 

Before:

<!-- FILE NAME SUGGESTIONS: * node--236--full.html.twig * node--236.html.twig x node--page--full.html.twig * node--page.html.twig * node--full.html.twig * node.html.twig --> 

After:

<!-- FILE NAME SUGGESTIONS: * node--236--full--site-default.html.twig * node--236--site-default.html.twig * node--page--full--site-default.html.twig * node--page--site-default.html.twig * node--full--site-default.html.twig * node--236--full.html.twig * node--236.html.twig x node--page--full.html.twig * node--page.html.twig * node--full.html.twig * node.html.twig --> 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.