Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Add a config for specifying the default layout #11025

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,15 @@

'fake_sql_queries' => config('app.debug'),

/*
|--------------------------------------------------------------------------
| Layout
|--------------------------------------------------------------------------
|
| Define the default layout that will be used by views.
|
*/

'layout' => env('STATAMIC_LAYOUT', 'layout'),

];
2 changes: 1 addition & 1 deletion src/Entries/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ public function layout($layout = null)
return $this
->fluentlyGetOrSet('layout')
->getter(function ($layout) {
return $layout ?? 'layout';
return $layout ?? config('statamic.system.layout', 'layout');
})
->args(func_get_args());
}
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/FrontendController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function route(Request $request, ...$args)

$view = app(View::class)
->template($view)
->layout(Arr::get($data, 'layout', 'layout'))
->layout(Arr::get($data, 'layout', config('statamic.system.layout', 'layout')))
->with($data)
->cascadeContent($this->getLoadedRouteItem($data));

Expand Down
2 changes: 1 addition & 1 deletion src/Taxonomies/Taxonomy.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public function layout($layout = null)
return $this
->fluentlyGetOrSet('layout')
->getter(function ($layout) {
return $layout ?? 'layout';
return $layout ?? config('statamic.system.layout', 'layout');
})
->args(func_get_args());
}
Expand Down
12 changes: 12 additions & 0 deletions tests/Routing/RoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,16 @@ public function it_loads_term_by_binding()
$this->get('/bindings/term/title/Blog2')
->assertNotFound();
}

#[Test]
public function it_uses_a_non_default_layout()
{
config()->set('statamic.system.layout', 'custom-layout');
$this->viewShouldReturnRaw('custom-layout', 'Custom layout {{ template_content }}');
$this->viewShouldReturnRaw('test', 'Hello {{ hello }}');

$this->get('/basic-route-with-data')
->assertOk()
->assertSee('Custom layout');
}
}
Loading