Skip to content
Open
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
17 changes: 17 additions & 0 deletions config/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,4 +269,21 @@

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

/*
|--------------------------------------------------------------------------
| Blueprint Templates
|--------------------------------------------------------------------------
|
| When an entry's template is set to `@blueprint`, Statamic will look for
| a view named `{collection}.{blueprint}`. You may override this logic
| on a per-collection basis here.
|
| https://statamic.dev/content-modeling/collections#templates
|
*/

'blueprint_templates' => [
//
],

];
5 changes: 4 additions & 1 deletion src/Entries/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,10 @@ public function template($template = null)

protected function inferTemplateFromBlueprint()
{
$template = $this->collection()->handle().'.'.$this->blueprint();
$handle = $this->collection()->handle();
$prefix = config('statamic.system.blueprint_templates.'.$handle, $handle);

$template = $prefix.'.'.$this->blueprint();

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

Expand Down
29 changes: 29 additions & 0 deletions tests/Data/Entries/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2048,6 +2048,35 @@ 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_path_per_collection()
{
config(['statamic.system.blueprint_templates' => [
'articles' => 'custom.path',
]]);

$articles = tap(Collection::make('articles')->template('@blueprint'))->save();
$pages = tap(Collection::make('pages')->template('@blueprint'))->save();
$blueprint = tap(Blueprint::make('standard_article')->setNamespace('collections.articles'))->save();

$articleEntry = Entry::make('test')->collection($articles)->blueprint($blueprint->handle());
$pageEntry = Entry::make('test')->collection($pages)->blueprint($blueprint->handle());

// mapped collection uses the mapped prefix instead of the collection handle
$this->assertEquals('custom.path.standard_article', $articleEntry->template());

// unmapped collection still uses its handle as the prefix
$this->assertEquals('pages.standard_article', $pageEntry->template());

// mapped collection uses slugified prefix when that template exists
View::shouldReceive('exists')->with('custom.path.standard-article')->andReturn(true);
$this->assertEquals('custom.path.standard-article', $articleEntry->template());

// entry level template still overrides @blueprint
$articleEntry->template('articles.custom');
$this->assertEquals('articles.custom', $articleEntry->template());
}

#[Test]
public function it_gets_and_sets_the_layout()
{
Expand Down
Loading