Skip to content

Commit

Permalink
Add a config for specifying the default layout
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Oct 29, 2024
1 parent f8c6108 commit b39f4eb
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
10 changes: 10 additions & 0 deletions config/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@

'middleware' => 'web',

/*
|--------------------------------------------------------------------------
| Layout
|--------------------------------------------------------------------------
|
| Define the default layout that will be used by front end routes.
|
*/

'layout' => env('STATAMIC_FRONTEND_ROUTES_LAYOUT', 'layout'),
];
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.routes.layout', 'layout')))
->with($data)
->cascadeContent($this->getLoadedRouteItem($data));

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.routes.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 b39f4eb

Please sign in to comment.