Skip to content

Commit 6ef2251

Browse files
committed
Added support for plugins (right now it automatically uses plugin view files if in plugin)
1 parent a3c1b46 commit 6ef2251

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

View/Helper/MustacheHelper.php

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,35 @@ public function __construct(View $View, $options = array()) {
4040
App::import('Vendor', 'Mustache.mustache/src/Mustache/Autoloader');
4141
Mustache_Autoloader::register();
4242

43-
43+
$this->View = $View;
44+
4445
$viewPath = App::path('View');
45-
$partialsPath = $viewPath[0].'Elements';
46+
$viewPath = $viewPath[0];
4647

48+
$viewPath = $this->checkPluginPath($viewPath);
49+
50+
$partialsPath = $viewPath.'Elements';
4751
$this->m = new Mustache_Engine(array(
4852
'partials_loader' => new Mustache_Loader_FilesystemLoader($partialsPath),
4953
));
5054
}
5155

56+
/**
57+
* Take a path as default, and check if we should be looking in a plugin for elements instead.
58+
*/
59+
private function checkPluginPath($viewPath) {
60+
61+
// check if we're in plugin and change partials path if we are
62+
if ($plugin = $this->View->plugin) {
63+
$pluginPath = App::path('Plugin');
64+
$pluginPath = $pluginPath[0];
65+
$viewPath = $pluginPath.$plugin.'/View/';
66+
}
67+
68+
return $viewPath;
69+
70+
}
71+
5272
/** Returns the rendered template as HTML.
5373
* All variables should be 'set' by the CakePHP Controller
5474
*
@@ -110,6 +130,9 @@ private function _getElementPath( $element ) {
110130
$element = str_replace('__', '/', $element);
111131
$app_path = App::path('View');
112132
$app_path = $app_path[0];
133+
134+
$app_path = $this->checkPluginPath($app_path);
135+
113136
return $app_path . 'Elements' . DS . $element . '.' . $this->ext;
114137
}
115138

0 commit comments

Comments
 (0)