Skip to content

[5.x] Add configurable @blueprint template base path #11632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 5.x
Choose a base branch
from
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
14 changes: 14 additions & 0 deletions config/system.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),

];
5 changes: 4 additions & 1 deletion src/Entries/Entry.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
20 changes: 20 additions & 0 deletions tests/Data/Entries/EntryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down