Multisite inheritance question

Indeed handy with the ironing!

Regarding {{theme_url}} for in your case css, as @Sommerregen mentioned many plugins & themes does things differently, like i use the theme:// for all assets possible, and therefore i think Grav looks towards my user/themes directly in every case. So when getting the streams overriding right this will probably make the scenario work, hopefully.

But here i’m a bit lost, and only way i could use the subpage theme for the subpage was to add direct paths (just for test) as

$theme = "user/themes/gallery";

if (is_dir(__DIR__ . "/user/{$folder}/themes")) {
	$theme = "user/{$folder}/themes/gallery";
}

and then add

   'theme' => [
      'type' => 'ReadOnlyStream',
      'paths' => [
         "{$theme}",
      ]
   ] 

in return [].
But it only works if i disable/rename the user/themes/gallery folder… So, a bit lost, tho whit a good feeling.

@getluke, as i’m testing subdirectories i named it as followng user/sites/subsite and containing all content related to a standard grav setup.

A thought, do you need to set the full subdomain name on the folder for testing subdomains? Sounds weird to have user/sites/subsite.example.comas a folder name when it all depends on the location.

Had a bit of progress.
When disabling subsite/config/system.yamlwhile using previous direct paths for $theme, i do not longer need to disable/rename the user/themes/gallery folder. :+1: Feels reasonable to not have two system config files. And when plugins stream works for me i hope that admin only needs to be added in root site :slight_smile: If i missed something else, pleas let me know.

Ok, so digged a bit in plugin:// and added:

$plugin = "user/plugins";

if (is_dir(__DIR__ . "/user/{$folder}/plugins")) {
	$plugin = "user/{$folder}/plugins";
}

Then in return []

'plugin' => [
    'type' => 'Stream',
    'paths' => [
        "{$plugin}",
    ]
]            

So, do not know if this is the way to go, but it now can check if subsite plugins folder is present/not present and do accordingly.
However this evolved to the question, if there is a possibility to itterate over active subsite plugins, to see if the plugin exists in subsite/plugins - else use site/plugins path for that plugin. Wold that be a handy thing to have?

Also, the same way regarding themes, like how Grav works with plugin assets override from theme - eg when you simply can override one plugin template file from a theme just by adding and edit it, but in this scenario override site themes/plugins from subsite in a very familiar manner!

@-l-l-
A thought, do you need to set the full subdomain name on the folder for testing subdomains? Sounds weird to have user/sites/subsite.example.comas a folder name when it all depends on the location.

Yep, I’ll bet that is related to your problem. The setup.php file actually looks for a folder with the exact same string as your full subdomain. So for example if your subdomain is sub.example.com, your folder should be users/sites/sub.example.com.

But i do not use subdomain, i use subdirectory - as subdomain do not play at all on my setup. Even tested your approach on subdomain just for fun and named the folder sub.example.com - even if i would never do this just because of too much renaming on deploy.

Hi @getluke and @-l-l-,

indeed (otherwise noted in the docs - a typo) you need the full domain as the sub-directory. BTW I troubleshooted your problem @getluke . I come up with the following setup.php (please not the additions; with them Admin plugin plays nicely):

<?php
/**
 * Multisite setup for subsites accessible via sub-domains.
 *
 * DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!
 */

use Grav\Common\Utils;

// Get subsite name from sub-domain
$environment = isset($_SERVER['HTTP_HOST'])
    ? $_SERVER['HTTP_HOST']
    : (isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : 'localhost');
// Remove port from HTTP_HOST generated $environment
$environment = strtolower(Utils::substrToString($environment, ':'));
$folder = "sites/{$environment}"; 

if ($environment === 'localhost' || !is_dir(ROOT_DIR . "user/{$folder}")) {
     return [];
}

$themes = ["user/themes"];
if (is_dir(__DIR__ . "/user/{$folder}/themes")) {
    array_unshift($themes, "user/{$folder}/themes");
}

$plugins = ["user/plugins"];
if (is_dir(__DIR__ . "/user/{$folder}/plugins")) {
    array_unshift($plugins, "user/{$folder}/plugins");
}

return [
    'environment' => $environment,
    'streams' => [
        'schemes' => [
            'user' => [
               'type' => 'ReadOnlyStream',
               'prefixes' => [
                   '' => ["user/{$folder}"],
               ]
            ],
            'environment' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ["user/{$folder}"],
                ]
            ],
            'themes' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => $themes
                ]
            ],
            'plugins' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => $plugins
                ]
            ],
            'plugin' => [
                'type' => 'ReadOnlyStream',
                'prefixes' => [
                    '' => ['plugins://']
                ]
            ]
        ]
    ]
];

@-l-l- For the moment you can’t use the sub-directory approach with the Admin plugin. this is because you have to rewrite the full URL before Grav is actually initialized. This can be done. To be honest I already have a powerful setup.php, which does this. However although this part is finished it needs to be more polished. My plan is once Admin Pro is out to release it as an addition. Then it will become easy to setup new sites with just a few clicks.

It also addresses the naming of the folders. The examples in the docs are just examples. If you don’t like them you can alter the way how the $environment variable is constructed.

1 Like

@-l-l- Setting up a site with sub-domains should be easy. Just configure them as usual and point them to the grav install (root directory e.g. html/grav). The rest does Grav.

But if you really insist on having subfolders as mutliple sites you either have to write up something for your own or put every sub-site into a different folder and consider Themer to use different themes.

Just started to play with directories as subdomains only give med “This site can’t be reached” so far ^^

Did you used my setup.php? It should work, really. Make sure that there is a user/sites/<subsite.with.domain>/pages folder.

digging in to it, thinking it is my virtual host messing the subdomain up…

@-l-l- when using subdomains keep this in mind from the docs:

If you choose sub-domains for structuring your website network, then you will have to configure (wildcard) sub-domains on your server in addition to the setup of your subsites in your user/sites directory.

How you do this depends on your environment, but I use MAMP Pro to setup local environments and it’s super easy to handle subdomains using the Alias feature.

omg lol, sometimes is very nice to lear something new like vhost server alias can handle multiple urls, and wildcard! as always, many thanks for inputs.

@Sommerregen, very valid approach to make a pro plugin for it!
However subdir was just for educational purpose, now subdom is up and running and probably better for anything.

So about the previous mention regarding overriding plugins / themes or just parts of them from subdomain - eg, if a needed folder (or file) is missing from subdom -> get it from main. Would this be a valid thing to do from setup.php?

@-l-l- Glad you sorted it :smiley: I think you can now try it on your own. Use the above setup.php and create a theme in your subsite themes folder using theme inheritance and you will see some magic;)

oh there we got some goodies :smiley: really nice!

Thanks for erything! Ill mos def read up

i’m totally lost. ok so i past your setup.phpon the folder www.

If i had a domain name with : www.toto.com
and a subdomain www.blog.toto.com

I have to create a folder in user named sites/blog.toto/pages ?

that’s right ?

You need two folders actually. One user/sites/toto.com and another one user/sites/blog.toto.com with its own pages, accounts and config folders. Themes and plugins are shared between these two sites, but each can have its own themes and plugins in their folders themes and plugins respectively.

Wait, maybe you have to add the www in front, e.g. user/sites/www.toto.com and user/sites/www.blog.toto.com.

So each domain and subdomain will have its own admin control panel ? ( i’m trying the thing your wrote )