diff options
author | mattab <matthieu.aubry@gmail.com> | 2014-05-09 09:44:23 +0400 |
---|---|---|
committer | mattab <matthieu.aubry@gmail.com> | 2014-05-09 09:44:23 +0400 |
commit | 0cbd5f0642a0d137751a028c3bf4ca30d265918c (patch) | |
tree | f930a6119cfed208e8659b91c6da41e99c475612 /core/Twig.php | |
parent | 47f7d2c3afc5785cb8db9b77928856745b77bacc (diff) | |
parent | 6899ba9ed1b2cb78cb2ffc0578c6cee21d8fad4c (diff) |
Merge branch 'master' of https://github.com/datamintsGmbH/piwik into datamintsGmbH-master
Diffstat (limited to 'core/Twig.php')
-rwxr-xr-x[-rw-r--r--] | core/Twig.php | 56 |
1 files changed, 51 insertions, 5 deletions
diff --git a/core/Twig.php b/core/Twig.php index a560daa2ce..a9b7988b77 100644..100755 --- a/core/Twig.php +++ b/core/Twig.php @@ -38,11 +38,25 @@ class Twig public function __construct() { $loader = $this->getDefaultThemeLoader(); - - $this->addPluginNamespaces($loader); - - // If theme != default we need to chain - $chainLoader = new Twig_Loader_Chain(array($loader)); + $this->addPluginNamespaces($loader); + + //get current theme + $manager = Plugin\Manager::getInstance(); + $theme = $manager->getThemeEnabled(); + $loaders = array(); + + //create loader for custom theme to overwrite twig templates + if($theme->getPluginName() != \Piwik\Plugin\Manager::DEFAULT_THEME){ + $customLoader = $this->getCustomThemeLoader($theme); + if($customLoader){ + //make it possible to overwrite plugin templates + $this->addCustomPluginNamespaces($customLoader,$theme->getPluginName()); + $loaders[] = $customLoader; + } + } + $loaders[] = $loader; + + $chainLoader = new Twig_Loader_Chain($loaders); // Create new Twig Environment and set cache dir $templatesCompiledPath = PIWIK_USER_PATH . '/tmp/templates_c'; @@ -166,6 +180,22 @@ class Twig return $themeLoader; } + /** + * create template loader for a custom theme + * @param \Piwik\Plugin $theme + * @return \Twig_Loader_Filesystem + */ + protected function getCustomThemeLoader(Plugin $theme){ + if(!file_exists(sprintf("%s/plugins/%s/templates/", PIWIK_INCLUDE_PATH, $theme->getPluginName()))){ + return false; + } + $themeLoader = new Twig_Loader_Filesystem(array( + sprintf("%s/plugins/%s/templates/", PIWIK_INCLUDE_PATH, $theme->getPluginName()) + )); + + return $themeLoader; + } + public function getTwigEnvironment() { return $this->twig; @@ -300,6 +330,22 @@ class Twig } } + /** + * + * Plugin-Templates can be overwritten by putting identically named templates in plugins/[theme]/templates/plugins/[plugin]/ + * + */ + private function addCustomPluginNamespaces(Twig_Loader_Filesystem $loader, $pluginName) + { + $plugins = \Piwik\Plugin\Manager::getInstance()->getAllPluginsNames(); + foreach ($plugins as $name) { + $path = sprintf("%s/plugins/%s/templates/plugins/%s/", PIWIK_INCLUDE_PATH, $pluginName, $name); + if (is_dir($path)) { + $loader->addPath(PIWIK_INCLUDE_PATH . '/plugins/' . $pluginName . '/templates/plugins/'. $name , $name); + } + } + } + /** * Prepend relative paths with absolute Piwik path * |