[Howto] Individual themes per domain

Nextcloud has a cool theming option to provide a custom style including wallpaper, name, colour, …

Is there any option, maybe in the config files to create different theming styles per accessing domain one the same instance?

For example:

and both URLs would point to the same NC-instance? is this what you want to achieve? just a change of the theming but everything else would be the same?

Exactly it is!

I did this with a config/domains.config.php and different folders in the theme directory

<?php
    $CONFIG['trusted_domains'] = array (
    0 => 'domain1',
    1 => 'domain2'
);
if (isset($_SERVER['HTTP_HOST'])) {
    switch ($_SERVER['HTTP_HOST']) {
        case 'domain1':
            $CONFIG['theme']='domain1';
            $CONFIG['mail_from_address'] = 'address';
            $CONFIG['mail_domain'] = 'domain1';
            break;
        case 'domain2':
            //same for domain2
    }
}

Hi HeisenbergDO,

your solution looks perfect for me. I Like to do the same but get some Errors.
Could you give me some more Information? How looks your config.php ? Did you add something else there?

Thx

Rob

@RobiRob,

Its not tricky.

Add all Domains to $CONFIG[‘trusted_domains’][]. You can do this with config/config.php or in the first lines in config/domains.config.php.

'trusted_domains' =>
    array (
        0 => 'cloud.domain1.com',
        1 => 'cloud.domain2.com',
        2 => 'cloud.domain3.com',
        3 => 'cloud.domain4.com',
),

In config/domains.config.php

# if not set in config/config.php
$CONFIG['trusted_domains'] = array (
    0 => 'cloud.domain1.com',
    1 => 'cloud.domain2.com',
    2 => 'cloud.domain3.com',
    3 => 'cloud.domain4.com',
);

if (isset($_SERVER['HTTP_HOST'])) {
    switch ($_SERVER['HTTP_HOST']) {
        # Server called with cloud.domain1.com
        case 'cloud.domain1.com':
            # sure, we can do more stuff like checking an existing
            # directory in the themes directory

            # use this theme (must exists in themes/ )
            $CONFIG['theme']='cloud.domain1.com';
            # configure local-part of email address
            $CONFIG['mail_from_address'] = 'no-reply';
            # configure domain of email address
            $CONFIG['mail_domain'] = 'domain1.com';
            break;
        case 'cloud.domain2.com':
            $CONFIG['theme']='cloud.domain2.com';
            $CONFIG['mail_from_address'] = 'no-reply';
            $CONFIG['mail_domain'] = 'domain2.com';
            break;
        # and so on for other domains
    }
}

The directory “themes/domain1.com” contains the following files:
themes/domain1.com/defaults.php
themes/domain1.com/core/apps/img/favicon-touch.png
themes/domain1.com/core/css/server.css
themes/domain1.com/core/img/favicon.ico
themes/domain1.com/core/img/logo.svg
themes/domain1.com/core/img/domain1.com-norm.svg
themes/domain1.com/core/img/favicon-touch.png
themes/domain1.com/core/img/domain1.com-logo.svg
themes/domain1.com/core/img/favicon-64.png
themes/domain1.com/core/img/favicon-16.png
themes/domain1.com/core/img/domain1.com-logo-wide.svg
themes/domain1.com/core/img/favicon-128.png
themes/domain1.com/core/img/favicon-256.png
themes/domain1.com/core/img/favicon-32.png
themes/domain1.com/core/img/favicon.png

themes/domain1.com/defaults.php:

<?php
class OC_Theme {
    # for a list of functions see /lib/private/defaults.php
   function __construct() {
   }
   public function getTitle() {
       return "My Own Nextcloud";
   }
   public function getName() {
       return "Best-Cloud";
   }
   public function getHTMLName() {
       return "Best-Cloud";
   }
   public function getEntity() {
       // Footer-Name
       return "My Company";
   }
   public function getSlogan() {
       return "We do everything for you :-)";
   }
   public function getLongFooter() {
       return $this->getShortFooter();
   }
   public function getShortFooter() {
       return '<a href="https://domain1.com" target="_blank" rel="noreferrer">' . $this->getEntity() . '</a> - ' . $this->getSlogan();
   }
   public function getLogoClaim() {
       return '';
   }

}

3 Likes

Hi HeisenbergDo

Thank you very much. It Woks. :slight_smile:

Kind regards

Rob

This works also for different email settings for each domain:

# cat domains.config.php 

<?php
if (isset($_SERVER['HTTP_HOST'])) {
    switch ($_SERVER['HTTP_HOST']) {
        # Server called with cloud.domain1.com
        case 'domain1.de':
            $CONFIG['mail_from_address'] = '*****';
            $CONFIG['mail_domain'] = 'domain1.de';
            $CONFIG['mail_smtpname'] = '******';
            $CONFIG['mail_smtppassword'] = '******';
            break;
        case 'domain2.de':
            $CONFIG['mail_from_address'] = '*****';
            $CONFIG['mail_domain'] = 'domain2.de';
            $CONFIG['mail_smtpname'] = '******';
            $CONFIG['mail_smtppassword'] = '******';
            break;
        # and so on for other domains
    }
}

2 Likes

Looks like the config.php gets reseted when you do an update of nextcloud :frowning:

That shouldn’t happen, so that’s an issue you should resolve. I would start a topic on it.

Thanks @HeisenbergDo,

your example helped me a lot, when trying to achieve something similar.
I was able to successfully change colors and texts, but up to now, I was unable to set different logos or favicons, the nextcloud default svg is always the logo instead.

In fact, none of those files in the img folder is ever used.

root@server:/var/www/nextcloud/themes/domain1# tree
.
├── core
│   ├── css
│   │   └── server.css
│   └── img
│       ├── favicon.ico
│       ├── favicon.png
│       ├── favicon.svg
│       ├── favicon-touch.png
│       ├── favicon-touch.svg
│       ├── logo-icon.png
│       ├── logo-icon.svg
│       ├── logo-mail.gif
│       ├── logo.png
│       └── logo.svg
└── defaults.php

3 directories, 12 files

I’m running Nextcloud 16.0.4 on Ubuntu 18.04 LTS with nginx and mariadb.
Maybe you can help me?

Thanks! :slight_smile:

Hi, @eehmke was so kind and pointed me to this thread, haven’t found myself before.

Seems to be exactly what I’ve asked here: “Is it possible to have different background images for login page, based on / for each trusted_domains?

Questions left for me:

  • Which $CONFIG element is the WALLPAPER / background image? Can’t find in config.php, and also can’t find any picture in folder structure. Stored in database?
  • Am I right that you don’t need to define ALL $CONFIG elements for each domain in trusted_domains? If some are undefined, do they stay on the default / inherit their default value? Or do I have to define a complete $CONFIG set, even if I only want to change the wallpaper and all other should be nextcloud’s defaults?

Thanks,
Michael

Hi, have you found the answers in the meantime?