Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorThomas Steur <thomas.steur@googlemail.com>2014-08-13 13:44:21 +0400
committerThomas Steur <thomas.steur@googlemail.com>2014-08-13 13:44:21 +0400
commit42fb686b6708f3e5ce3a1364681c9d182d771ca3 (patch)
treee15d50cddf7d635898a09fe398ed78af6a168024 /core
parent1d2524063fd84ca90d9dbbf09962e9e780c4dc0d (diff)
added method again with a better - and more unique - name
Diffstat (limited to 'core')
-rw-r--r--core/Plugin/Controller.php39
1 files changed, 39 insertions, 0 deletions
diff --git a/core/Plugin/Controller.php b/core/Plugin/Controller.php
index 5521eaf0c2..7b6298dfe7 100644
--- a/core/Plugin/Controller.php
+++ b/core/Plugin/Controller.php
@@ -249,6 +249,45 @@ abstract class Controller
}
/**
+ * Assigns the given variables to the template and renders it.
+ *
+ * Example:
+ * ```
+ public function myControllerAction () {
+ return $this->renderTemplate('index', array(
+ 'answerToLife' => '42'
+ ));
+ }
+ ```
+ * This will render the 'index.twig' file within the plugin templates folder and assign the view variable
+ * `answerToLife` to `42`.
+ *
+ * @param string $template The name of the template file. If only a name is given it will automatically use
+ * the template within the plugin folder. For instance 'myTemplate' will result in
+ * '@$pluginName/myTemplate.twig'. Alternatively you can include the full path:
+ * '@anyOtherFolder/otherTemplate'. The trailing '.twig' is not needed.
+ * @param array $variables For instance array('myViewVar' => 'myValue'). In template you can use {{ myViewVar }}
+ * @return string
+ * @since 2.5.0
+ * @api
+ */
+ protected function renderTemplate($template, array $variables = array())
+ {
+ if (false === strpos($template, '@') || false === strpos($template, '/')) {
+ $template = '@' . $this->pluginName . '/' . $template;
+ }
+
+ $view = new View($template);
+ $this->setBasicVariablesView($view);
+
+ foreach ($variables as $key => $value) {
+ $view->$key = $value;
+ }
+
+ return $view->render();
+ }
+
+ /**
* Convenience method that creates and renders a ViewDataTable for a API method.
*
* @param string|\Piwik\Plugin\Report $apiAction The name of the API action (eg, `'getResolution'`) or