Skip to content

Commit 351301c

Browse files
Handle multisite entries.
1 parent 7d9e738 commit 351301c

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/ServiceProvider.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,26 @@ protected function registerServices()
2929
}
3030

3131
/**
32-
* Extract the Statamic template data for the
33-
* current entry and pass it to our singleton.
32+
* Process the view data that has been set up
33+
* by Statamic. This is very convoluted but
34+
* it's efficient!
3435
*/
3536
protected function registerViewComposers()
3637
{
3738
// Append slash to path if necessary
3839
$path = substr(request()->path(), 0, 1) == '/' ? request()->path() : '/' . request()->path();
40+
41+
// Remove multisite url prefixes if necessary (we can't find entries by uri when they are prefixed)
42+
foreach(\Statamic\Facades\Site::all() as $site) {
43+
44+
$sitePrefix = str_replace(request()->root(), '', $site->url);
45+
46+
if(strlen($sitePrefix) && str_starts_with($path, $sitePrefix)) {
47+
$path = substr($path, strlen($sitePrefix));
48+
}
49+
50+
}
51+
3952
$template = null;
4053

4154
if($entry = Entry::findByUri($path)) {

0 commit comments

Comments
 (0)