Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 34 additions & 11 deletions Sources/Theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -507,25 +507,48 @@ public static function loadSubTemplates(): void
public static function loadSubTemplate(string|array $sub_template_name, bool|string $fatal = false): void
{
$template_name = \is_array($sub_template_name) ? $sub_template_name[0] : $sub_template_name;
$function_params = \is_array($sub_template_name) ? ($sub_template_name[1] ?? []) : [];

// Add the sub-template to the debug context if debugging is enabled.
if (DebugUtils::isDebugEnabled()) {
DebugUtils::addDebugSource('sub_templates', $template_name);
}

// Determine the template function name and any associated parameters.
if (\is_array($sub_template_name)) {
$theme_function = 'template_' . $sub_template_name[0];
$function_params = $sub_template_name[1] ?? [];
} else {
$theme_function = 'template_' . $sub_template_name;
$function_params = [];
$template_loaded = false;

if (\is_string($template_name) && \str_contains($template_name, '::')) {
$template_name = preg_replace_callback(
'/(#?)_(above|below)$/i',
fn($m) => ucfirst($m[2]) . $m[1],
$template_name
);

$callable = Utils::getCallable($template_name);

if ($callable !== false) {
if (empty($function_params)) {
\call_user_func($callable);
} else {
\call_user_func_array($callable, $function_params);
}

$template_loaded = true;
}
}

// Attempt to call the sub-template function.
if (\is_callable($theme_function)) {
\call_user_func_array($theme_function, $function_params);
} else {
if (! $template_loaded) {
Comment thread
dragomano marked this conversation as resolved.
Outdated
$theme_function = 'template_' . $template_name;

$callable = Utils::getCallable($theme_function);

if ($callable !== false) {
\call_user_func_array($theme_function, $function_params);

$template_loaded = true;
}
}

if (! $template_loaded) {
Comment thread
dragomano marked this conversation as resolved.
Outdated
// Handle errors based on the $fatal parameter.
if ($fatal === false) {
ErrorHandler::fatalLang(
Expand Down
9 changes: 7 additions & 2 deletions Themes/default/Admin.template.php
Original file line number Diff line number Diff line change
Expand Up @@ -872,8 +872,13 @@ function ($v)
// Hang about? Are you pulling my leg - a callback?!
if (is_array($config_var) && $config_var['type'] == 'callback')
{
if (function_exists('template_callback_' . $config_var['name']))
call_user_func('template_callback_' . $config_var['name']);
$callbackName = $config_var['name'];
if (function_exists('template_callback_' . $callbackName)) {
$callbackName = 'template_callback_' . $callbackName;
}

$callable = Utils::getCallable($callbackName);
Comment thread
dragomano marked this conversation as resolved.
Outdated
$callable && call_user_func($callable);

continue;
}
Expand Down