header('Content-Type: application/javascript');
header("Cache-Control: max-age=$year, public");
- print CRM_Core_Page_AJAX::returnDynamicJS('CRM/common/navigation.js.tpl', array(
+ print CRM_Core_Smarty::singleton()->fetchWith('CRM/common/navigation.js.tpl', array(
'navigation' => CRM_Core_BAO_Navigation::createNavigation($contactID),
));
}
CRM_Utils_System::civiExit();
}
- /**
- * Render and output a template as a javascript file
- * @param string $tplFile
- * @param array $vars - template variables
- */
- static function returnDynamicJS($tplFile, $vars = array()) {
- $smarty = CRM_Core_Smarty::singleton();
- foreach ($vars as $name => $val) {
- $smarty->assign($name, $val);
- }
- return $smarty->fetch($tplFile);
- }
-
/**
* Send autocomplete results to the client. Input can be a simple or nested array.
* @param array $results - If nested array, also provide:
'otherSearch' => json_encode(ts('Enter search term...')),
'contactCreate' => CRM_Core_BAO_UFGroup::getCreateLinks(),
);
- CRM_Utils_File::addDynamicResource($fileName, CRM_Core_Page_AJAX::returnDynamicJS('CRM/common/localization.js.tpl', $vars));
+ CRM_Utils_File::addDynamicResource($fileName, CRM_Core_Smarty::singleton()->fetchWith('CRM/common/localization.js.tpl', $vars));
}
/**
return $output;
}
+ /**
+ * Fetch a template (while using certain variables)
+ *
+ * @param string $resource_name
+ * @param array $vars (string $name => mixed $value) variables to export to Smarty
+ * @throws Exception
+ * @return bool|mixed|string
+ */
+ function fetchWith($resource_name, $vars) {
+ $this->pushScope($vars);
+ try {
+ $result = $this->fetch($resource_name);
+ } catch (Exception $e) {
+ // simulate try { ... } finally { ... }
+ $this->popScope();
+ throw $e;
+ }
+ $this->popScope();
+ return $result;
+ }
+
/**
* @param $name
* @param $value