File tree Expand file tree Collapse file tree 3 files changed +38
-1
lines changed
Expand file tree Collapse file tree 3 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 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];
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 {
You can’t perform that action at this time.
0 commit comments