Skip to content

Commit

Permalink
[5.x] Add a config for specifying the default layout (#11025)
Browse files Browse the repository at this point in the history
Co-authored-by: Jason Varga <jason@pixelfear.com>
  • Loading branch information
ryanmitchell and jasonvarga authored Nov 1, 2024
1 parent f74cd05 commit ce21344
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
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');
}
}

0 comments on commit ce21344

Please sign in to comment.