Skip to content

Commit b2f56c1

Browse files
committed
Add configurable @blueprint template base path
Adds a new configuration option to customize where Statamic looks for templates when using `@blueprint` in collections.
1 parent 288a770 commit b2f56c1

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

Diff for: config/system.php

+14
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,18 @@
218218

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

221+
/*
222+
|--------------------------------------------------------------------------
223+
| Blueprint Template Base Path
224+
|--------------------------------------------------------------------------
225+
|
226+
| When using @blueprint in a collection's template setting, Statamic looks for
227+
| templates in /resources/views/{collection}/{blueprint}.antlers.html. Set this
228+
| value to use a different base path
229+
| (e.g. 'templates' for /resources/views/templates/).
230+
|
231+
*/
232+
233+
'blueprint_template_base_path' => env('STATAMIC_BLUEPRINT_TEMPLATE_PATH', null),
234+
221235
];

Diff for: src/Entries/Entry.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,10 @@ public function template($template = null)
528528

529529
protected function inferTemplateFromBlueprint()
530530
{
531-
$template = $this->collection()->handle().'.'.$this->blueprint();
531+
$basePath = config('statamic.system.blueprint_template_base_path');
532+
$prefix = $basePath ?: $this->collection()->handle();
533+
534+
$template = $prefix.'.'.$this->blueprint();
532535

533536
$slugifiedTemplate = str_replace('_', '-', $template);
534537

Diff for: tests/Data/Entries/EntryTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -1915,6 +1915,26 @@ public function it_gets_and_sets_an_inferred_template_from_blueprint()
19151915
$this->assertEquals('articles.custom', $entry->template());
19161916
}
19171917

1918+
#[Test]
1919+
public function it_respects_custom_blueprint_template_base_path()
1920+
{
1921+
// Set custom base path for test
1922+
config(['statamic.system.blueprint_template_base_path' => 'custom.path']);
1923+
1924+
$collection = tap(Collection::make('articles')->template('@blueprint'))->save();
1925+
$blueprint = tap(Blueprint::make('standard_article')->setNamespace('collections.articles'))->save();
1926+
$entry = Entry::make('test')->collection($collection)->blueprint($blueprint->handle());
1927+
1928+
// entry uses the custom path instead of collection handle
1929+
$this->assertEquals('custom.path.standard_article', $entry->template());
1930+
1931+
// entry uses slugified custom path when that template exists
1932+
View::shouldReceive('exists')->with('custom.path.standard-article')->andReturn(true);
1933+
$this->assertEquals('custom.path.standard-article', $entry->template());
1934+
1935+
config(['statamic.system.blueprint_template_base_path' => null]);
1936+
}
1937+
19181938
#[Test]
19191939
public function it_gets_and_sets_the_layout()
19201940
{

0 commit comments

Comments
 (0)