diff --git a/src/Application/UI/Presenter.php b/src/Application/UI/Presenter.php index 57c8b8737..624ea3640 100644 --- a/src/Application/UI/Presenter.php +++ b/src/Application/UI/Presenter.php @@ -565,6 +565,16 @@ protected function createTemplate(/*string $class = null*/): Template } + public function formatTemplateClass(): ?string + { + $class = preg_replace('#Presenter$#', ucfirst((string) $this->action) . 'Template', static::class); + if (class_exists($class) && is_a($class, Template::class, true)) { + return $class; + } + return parent::formatTemplateClass(); + } + + /********************* partial AJAX rendering ****************d*g**/ diff --git a/tests/UI/Presenter.formatTemplateClass.phpt b/tests/UI/Presenter.formatTemplateClass.phpt index 24125be96..a2dc0bc71 100644 --- a/tests/UI/Presenter.formatTemplateClass.phpt +++ b/tests/UI/Presenter.formatTemplateClass.phpt @@ -45,6 +45,9 @@ class CTemplate implements Nette\Application\UI\Template } } +class CBarTemplate extends CTemplate +{ +} test('without template', function () { $presenter = new APresenter; @@ -64,3 +67,13 @@ test('with template', function () { $presenter = new CPresenter; Assert::same(CTemplate::class, $presenter->formatTemplateClass()); }); + + +test('with action template', function () { + $presenter = new CPresenter; + $presenter->changeAction('Foo'); + Assert::same(CTemplate::class, $presenter->formatTemplateClass()); + + $presenter->changeAction('Bar'); + Assert::same(CBarTemplate::class, $presenter->formatTemplateClass()); +});