summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-03-25 18:19:31 -0400
committerFrederic Guillot <fred@kanboard.net>2016-03-25 18:19:31 -0400
commit407a51e6c45f411533b13176a614ed28e7cd460d (patch)
tree4210a93ed27ed4797921c76ee52125c5f314aca6
parent354e37971d43d3b62d8f4e2a23eff09e88525627 (diff)
Allow to use the original template in overridden templates (PR #1941)
-rw-r--r--ChangeLog1
-rw-r--r--app/Core/Template.php25
-rw-r--r--doc/plugin-overrides.markdown6
-rw-r--r--tests/units/Core/TemplateTest.php30
4 files changed, 38 insertions, 24 deletions
diff --git a/ChangeLog b/ChangeLog
index 327d2389..5fdbf6e3 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -9,6 +9,7 @@ New features:
Improvements:
+* Allow to use the original template in overridden templates
* Unification of the project header
* Refactoring of Javascript code
* Improve comments design
diff --git a/app/Core/Template.php b/app/Core/Template.php
index f85c7f28..cf5512d9 100644
--- a/app/Core/Template.php
+++ b/app/Core/Template.php
@@ -84,25 +84,26 @@ class Template
/**
* Find template filename
*
- * Core template name: 'task/show'
- * Plugin template name: 'myplugin:task/show'
+ * Core template: 'task/show' or 'kanboard:task/show'
+ * Plugin template: 'myplugin:task/show'
*
* @access public
- * @param string $template_name
+ * @param string $template
* @return string
*/
- public function getTemplateFile($template_name)
+ public function getTemplateFile($template)
{
- $template_name = isset($this->overrides[$template_name]) ? $this->overrides[$template_name] : $template_name;
+ $plugin = '';
+ $template = isset($this->overrides[$template]) ? $this->overrides[$template] : $template;
- if (strpos($template_name, ':') !== false) {
- list($plugin, $template) = explode(':', $template_name);
- $path = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'plugins';
- $path .= DIRECTORY_SEPARATOR.ucfirst($plugin).DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.$template.'.php';
- } else {
- $path = __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.$template_name.'.php';
+ if (strpos($template, ':') !== false) {
+ list($plugin, $template) = explode(':', $template);
}
- return $path;
+ if ($plugin !== 'kanboard' && $plugin !== '') {
+ return implode(DIRECTORY_SEPARATOR, array(__DIR__, '..', '..', 'plugins', ucfirst($plugin), 'Template', $template.'.php'));
+ }
+
+ return implode(DIRECTORY_SEPARATOR, array(__DIR__, '..', 'Template', $template.'.php'));
}
}
diff --git a/doc/plugin-overrides.markdown b/doc/plugin-overrides.markdown
index 722b4126..96a09e47 100644
--- a/doc/plugin-overrides.markdown
+++ b/doc/plugin-overrides.markdown
@@ -34,3 +34,9 @@ $this->template->setTemplateOverride('header', 'theme:layout/header');
```
The first argument is the original template name and the second argument the template to use as replacement.
+
+You can still use the original template using the "kanboard:" prefix:
+
+```php
+<?= $this->render('kanboard:header') ?>
+```
diff --git a/tests/units/Core/TemplateTest.php b/tests/units/Core/TemplateTest.php
index bd476c51..9584c831 100644
--- a/tests/units/Core/TemplateTest.php
+++ b/tests/units/Core/TemplateTest.php
@@ -8,35 +8,41 @@ class TemplateTest extends Base
{
public function testGetTemplateFile()
{
- $t = new Template($this->container['helper']);
+ $template = new Template($this->container['helper']);
+
+ $this->assertStringEndsWith(
+ implode(DIRECTORY_SEPARATOR, array('app', 'Core', '..', 'Template', 'a', 'b.php')),
+ $template->getTemplateFile('a'.DIRECTORY_SEPARATOR.'b')
+ );
+
$this->assertStringEndsWith(
- 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'a'.DIRECTORY_SEPARATOR.'b.php',
- $t->getTemplateFile('a'.DIRECTORY_SEPARATOR.'b')
+ implode(DIRECTORY_SEPARATOR, array('app', 'Core', '..', 'Template', 'a', 'b.php')),
+ $template->getTemplateFile('kanboard:a'.DIRECTORY_SEPARATOR.'b')
);
}
public function testGetPluginTemplateFile()
{
- $t = new Template($this->container['helper']);
+ $template = new Template($this->container['helper']);
$this->assertStringEndsWith(
- 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'Myplugin'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'a'.DIRECTORY_SEPARATOR.'b.php',
- $t->getTemplateFile('myplugin:a'.DIRECTORY_SEPARATOR.'b')
+ implode(DIRECTORY_SEPARATOR, array('app', 'Core', '..', '..', 'plugins', 'Myplugin', 'Template', 'a', 'b.php')),
+ $template->getTemplateFile('myplugin:a'.DIRECTORY_SEPARATOR.'b')
);
}
public function testGetOverridedTemplateFile()
{
- $t = new Template($this->container['helper']);
- $t->setTemplateOverride('a'.DIRECTORY_SEPARATOR.'b', 'myplugin:c');
+ $template = new Template($this->container['helper']);
+ $template->setTemplateOverride('a'.DIRECTORY_SEPARATOR.'b', 'myplugin:c');
$this->assertStringEndsWith(
- 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'plugins'.DIRECTORY_SEPARATOR.'Myplugin'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'c.php',
- $t->getTemplateFile('a'.DIRECTORY_SEPARATOR.'b')
+ implode(DIRECTORY_SEPARATOR, array('app', 'Core', '..', '..', 'plugins', 'Myplugin', 'Template', 'c.php')),
+ $template->getTemplateFile('a'.DIRECTORY_SEPARATOR.'b')
);
$this->assertStringEndsWith(
- 'app'.DIRECTORY_SEPARATOR.'Core'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'Template'.DIRECTORY_SEPARATOR.'d.php',
- $t->getTemplateFile('d')
+ implode(DIRECTORY_SEPARATOR, array('app', 'Core', '..', 'Template', 'd.php')),
+ $template->getTemplateFile('d')
);
}
}