From c22a0017beb391ed9734b67abf5b1bcfeb26d233 Mon Sep 17 00:00:00 2001 From: mattab Date: Fri, 14 Mar 2014 22:05:12 +1300 Subject: Allow templates postEvent() calls to also pass parameters. For example this is done in the twig template: ``` {{ postEvent("Template.jsGlobalVariables", minDateYear, maxDateYear) }} ``` and you can hook on this event, by doing: ``` public function addTrackingHostnamesToJs(&$out, $minDateYear, $maxDateYear) { // printout out the data as a comment for testing $out .= "/* " . $minDateYear . " - " . $maxDateYear . " */"; ``` --- core/Twig.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'core/Twig.php') diff --git a/core/Twig.php b/core/Twig.php index 4da7a364f8..16348e524c 100644 --- a/core/Twig.php +++ b/core/Twig.php @@ -118,8 +118,17 @@ class Twig protected function addFunction_postEvent() { $postEventFunction = new Twig_SimpleFunction('postEvent', function ($eventName) { + // get parameters to twig function + $params = func_get_args(); + // remove the first value (event name) + array_shift($params); + + // make the first value the string that will get output in the template + // plugins can modify this string $str = ''; - Piwik::postEvent($eventName, array(&$str)); + $params = array_merge( array( &$str ), $params); + + Piwik::postEvent($eventName, $params); return $str; }, array('is_safe' => array('html'))); $this->twig->addFunction($postEventFunction); -- cgit v1.2.3