From b2f56c1f9196bef44e00794107a1f889e0b5cd8d Mon Sep 17 00:00:00 2001 From: Oliver Mesieh Date: Fri, 28 Mar 2025 10:58:34 +0100 Subject: [PATCH] Add configurable `@blueprint` template base path Adds a new configuration option to customize where Statamic looks for templates when using `@blueprint` in collections. --- config/system.php | 14 ++++++++++++++ src/Entries/Entry.php | 5 ++++- tests/Data/Entries/EntryTest.php | 20 ++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/config/system.php b/config/system.php index fc04ee4b02..8ac907b405 100644 --- a/config/system.php +++ b/config/system.php @@ -218,4 +218,18 @@ 'layout' => env('STATAMIC_LAYOUT', 'layout'), + /* + |-------------------------------------------------------------------------- + | Blueprint Template Base Path + |-------------------------------------------------------------------------- + | + | When using @blueprint in a collection's template setting, Statamic looks for + | templates in /resources/views/{collection}/{blueprint}.antlers.html. Set this + | value to use a different base path + | (e.g. 'templates' for /resources/views/templates/). + | + */ + + 'blueprint_template_base_path' => env('STATAMIC_BLUEPRINT_TEMPLATE_PATH', null), + ]; diff --git a/src/Entries/Entry.php b/src/Entries/Entry.php index 27493c2bd4..55fafc2266 100644 --- a/src/Entries/Entry.php +++ b/src/Entries/Entry.php @@ -528,7 +528,10 @@ public function template($template = null) protected function inferTemplateFromBlueprint() { - $template = $this->collection()->handle().'.'.$this->blueprint(); + $basePath = config('statamic.system.blueprint_template_base_path'); + $prefix = $basePath ?: $this->collection()->handle(); + + $template = $prefix.'.'.$this->blueprint(); $slugifiedTemplate = str_replace('_', '-', $template); diff --git a/tests/Data/Entries/EntryTest.php b/tests/Data/Entries/EntryTest.php index ca48dd407d..de04a57ac2 100644 --- a/tests/Data/Entries/EntryTest.php +++ b/tests/Data/Entries/EntryTest.php @@ -1915,6 +1915,26 @@ public function it_gets_and_sets_an_inferred_template_from_blueprint() $this->assertEquals('articles.custom', $entry->template()); } + #[Test] + public function it_respects_custom_blueprint_template_base_path() + { + // Set custom base path for test + config(['statamic.system.blueprint_template_base_path' => 'custom.path']); + + $collection = tap(Collection::make('articles')->template('@blueprint'))->save(); + $blueprint = tap(Blueprint::make('standard_article')->setNamespace('collections.articles'))->save(); + $entry = Entry::make('test')->collection($collection)->blueprint($blueprint->handle()); + + // entry uses the custom path instead of collection handle + $this->assertEquals('custom.path.standard_article', $entry->template()); + + // entry uses slugified custom path when that template exists + View::shouldReceive('exists')->with('custom.path.standard-article')->andReturn(true); + $this->assertEquals('custom.path.standard-article', $entry->template()); + + config(['statamic.system.blueprint_template_base_path' => null]); + } + #[Test] public function it_gets_and_sets_the_layout() {