[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:

1 Like

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
    }
}
3 Likes

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

1 Like

@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 '';
   }

}

6 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
    }
}

4 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

1 Like

Hi, have you found the answers in the meantime?

I have applied the config likes described above:

Unfortunately it is not using the pictures like logo.png from the themes>domain>defaults.php What can I do?

How can I set the color individually per domain?

Editing the title in defaults.php or the Web UI works by the way.

Worked like a charm, thanks!!

Some notes/mistakes I made that may help other people.

  1. In ‘domains.config.php’, don’t forget to add <?php to the top. The post above that I was following from didn’t have it so the config was output as plain text.

  2. You need to disable the app Theming. It will override the manual theme you’ve made.

  3. The defaults.php from the thread didn’t work for me, maybe something changed since the posts or some hidden characters buggered it up in copying? I copied the example one in:
    /themes/example/defaults.php
    Made edits to that and everything was fine.

  4. I also copied the example css to my new themes and tweaked away:
    /themes/example/core/css/server.css

Beauty Howto guys, thanks!!

2 Likes

I’m noticing a problem with the per domain theming when it comes to the system emails. It does’t use the theme logo and the email template places the default NC logo for all the domains.

All the other text defined edits are correct in the emails. The logo even displays the correct alt text from getName() from the theme’s default.php. It is just the image it pulls is the core logo:
domain.com/core/img/logo=/logo.png?v=[some_kind_of_hash]

I see other people have had the same problem when doing manual themes so they switched to the theming app to resolve the logo in the email which isn’t useful with multi-domain.

I’m assuming a function needs to be added to the theme’s default.php that updates the logo path?
Cheers!

hi
sorry to dig that out
i’m trying to understand what you have achieved here, not regarding the theming, but the usage you’re doing of it …
do you have a single nextcloud server running and multiple domains accessing it, with seperate users and databases for each domain? … that’s what i’m trying to do ^^

It just shows a diffrent theme depending on which domain is used to access it. It is still the same Nextcloud instance, just with a diffrent theming. There is no real segregation if you do it like that.

You can’t do that with a single Nextcloud instance. For what you are trying to achive, you have to setup multiple separate Nextcloud instances. It is possible to that on a single server, but each of them have to be hosted in their own directories / webroots. Just like if you were hosting one or multiple websites next to Nextcloud on the same server.

1 Like

thanks a lot for your response
alas i couldn’t have a domain with cloudflare that accepts to be an alias … i’ll need to work it out …one more obstacle to simple life
i’m going to go with two different instances … as suggested
cheers

1 Like

all right i’m getting there ! at last !!!

theming has to be off
but i can’t find the way t add a login background image …

have you managed this?