I am a Grav newcomer and stuck on a problem for which I could not find any solution elsewhere. Hopefully, some of you may be able to help. At the moment I am trying to customize Grav in a way that I can have multiple subfolders, which in return contain more folders with my subsites. My folder structure looks like this:
- user
- sites
- v1
- sites
- subsitefolder1
- pages (folder)
- folder with actual pages inside
- pages (folder)
- subsitefolder2
- subsitefolder1
- sites
- v2
- sites
- subsitefolder
- sites
- v1
- sites
- ...
I used the official Grav guideline for a multisite setup and created the setup.php(for subdirectory) in Grav's root directory. But unfortunately, this only worked for sites which were at the level of my v1 folder. Sites which are located in folders on a deeper level, as my structure above requires, do not work.
Therefore I tried customizing the setup.php, so that it generates the new path correctly.
I thought that I matched the path to my folder structure accordingly, but sites are only displayed up to the level of subsitefolder1.
So v1/subsitefolder1 works, as it shows the landing page but even the actual URL for the landing page v1/subsitefolder1/landingpage does not work anymore.
I tried to change the path variables to include the newly added folder levels, which looked like it should work, as the generated Url matched the folder structure in the same ways the old setup.php did (plus additional folder level). But it did not work. This what my customized setup.php looks like at the moment:
<?php
/**
* Multisite setup for sub-directories or path based
* URLs for subsites.
*
* DO NOT EDIT UNLESS YOU KNOW WHAT YOU ARE DOING!
*/
use Grav\Common\Filesystem\Folder;
// Get relative path from Grav root.
$path = isset($_SERVER['PATH_INFO'])
? $_SERVER['PATH_INFO']
: Folder::getRelativePath($_SERVER['REQUEST_URI'], ROOT_DIR);
// Extract name of subsite from path
$name = Folder::shift($path);
$prefix = "/{$name}";
//add another layer for deeper subsites
$subsites= $name . '/' . $path . '/';
//concatenates $name sites and $path"
$urlwithsite=$name . '/' . 'sites/' . $path . '/';
// overwrite folder to contain whole path after user/
$folder = "sites/{$urlwithsite}";
if (!$name || !is_dir(ROOT_DIR . "user/{$folder}")) {
return [];
}
// Prefix all pages with the name of the subsite
$container['pages']->base($subsites);
return [
'environment' => $name,
'streams' => [
'schemes' => [
'user' => [
'type' => 'ReadOnlyStream',
'prefixes' => [
'' => ["user/{$folder}"],
]
]
]
]
];
The generated URL looks like it should be right, as it matches the folder structure, but it does not work properly.
Thanks in advance. Any advice is welcome.