Tpl: add fetch() method
This commit is contained in:
parent
3742ce7448
commit
24e3101dd0
1 changed files with 38 additions and 0 deletions
38
src/Tpl.php
38
src/Tpl.php
|
@ -444,6 +444,44 @@ class Tpl {
|
||||||
$sentry_span->finish();
|
$sentry_span->finish();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch a template
|
||||||
|
* @param string $template The template to fetch
|
||||||
|
* @param string|null $pagetitle The page title (optional)
|
||||||
|
* @param array $extra_args Extra arguments to use to compute the page title using sprintf
|
||||||
|
* @return string|false
|
||||||
|
*/
|
||||||
|
public static function fetch($template, $pagetitle=null, ...$extra_args) {
|
||||||
|
if (!$template) {
|
||||||
|
Log :: warning("Tpl::fetch(): No template specified.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$sentry_span = new SentrySpan('smarty.fetch_template', "Fetch Smarty template");
|
||||||
|
|
||||||
|
// If extra arguments passed, format pagetitle using sprintf
|
||||||
|
if ($pagetitle && $extra_args) {
|
||||||
|
$pagetitle = call_user_func_array(
|
||||||
|
'sprintf',
|
||||||
|
array_merge(array($pagetitle), $extra_args)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
$result = false;
|
||||||
|
$success = false;
|
||||||
|
try {
|
||||||
|
Hook :: trigger('before_fetching_template');
|
||||||
|
self :: define_common_variables($pagetitle);
|
||||||
|
$result = self :: $smarty->fetch("Tpl:$template");
|
||||||
|
$success = true;
|
||||||
|
}
|
||||||
|
catch (Exception $e) {
|
||||||
|
Log :: exception($e, "Smarty - An exception occured fetching template '$template'");
|
||||||
|
}
|
||||||
|
Hook :: trigger('after_fetching_template', array('success' => $success));
|
||||||
|
$sentry_span->finish();
|
||||||
|
return $success?$result:false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display AJAX return
|
* Display AJAX return
|
||||||
* @param array|null $data AJAX returned data (optional)
|
* @param array|null $data AJAX returned data (optional)
|
||||||
|
|
Loading…
Reference in a new issue