diff --git a/code/controllers/ContentController.php b/code/controllers/ContentController.php index c4e2c1f2..11e22cd7 100755 --- a/code/controllers/ContentController.php +++ b/code/controllers/ContentController.php @@ -402,15 +402,15 @@ HTML; if($action == "index") $action = ""; else $action = '_' . $action; - // Find templates by dataRecord - $templates = SSViewer::get_templates_by_class(get_class($this->dataRecord), $action, "SiteTree"); - - // Next, we need to add templates for all controllers - $templates += SSViewer::get_templates_by_class(get_class($this), $action, "Controller"); - - // Fail-over to the same for the "index" action - $templates += SSViewer::get_templates_by_class(get_class($this->dataRecord), "", "SiteTree"); - $templates += SSViewer::get_templates_by_class(get_class($this), "", "Controller"); + $templates = array_merge( + // Find templates by dataRecord + SSViewer::get_templates_by_class(get_class($this->dataRecord), $action, "SiteTree"), + // Next, we need to add templates for all controllers + SSViewer::get_templates_by_class(get_class($this), $action, "Controller"), + // Fail-over to the same for the "index" action + SSViewer::get_templates_by_class(get_class($this->dataRecord), "", "SiteTree"), + SSViewer::get_templates_by_class(get_class($this), "", "Controller") + ); return new SSViewer($templates); } diff --git a/tests/controller/ContentControllerTest.php b/tests/controller/ContentControllerTest.php index 8351c145..a39b34f6 100755 --- a/tests/controller/ContentControllerTest.php +++ b/tests/controller/ContentControllerTest.php @@ -168,6 +168,14 @@ class ContentControllerTest extends FunctionalTest { // to say the default Page.ss template $response = $self->get($page->RelativeLink("testwithouttemplate")); $self->assertEquals("Page", $response->getBody()); + + // Test that an action with a template will render the both action template *and* the + // correct parent template + $controller = new ContentController($page); + $viewer = $controller->getViewer('test'); + $templateList = array('ContentControllerTestPage_test', 'Page'); + $expected = SS_TemplateLoader::instance()->findTemplates($templateList, 'controllertest'); + $self->assertEquals($expected, $viewer->templates()); }); }