WHMCS-Smarty提取导致500内部服务器错误

时间:2018-09-30 12:45:28

标签: fetch smarty whmcs smarty3

我正在尝试从WHMCS的ClientAreaPage钩子覆盖smarty(smarty3)模板。但是,当我获取自定义模板时,它会不断加载,直到内存用完为止,并显示500个内部服务器错误!似乎无法弄清楚。

这是我的代码:

add_hook('ClientAreaPage', 1, function( $vars ) {
    global $smarty;

    //tried with "post" and "output" filter - without any luck.
    $smarty->registerFilter('pre','template_override_output_filter');
});

function template_override_output_filter($tpl_output, Smarty_Internal_Template $template) {
    global $smarty;

    $template_file_path = $template->_current_file;

    //getting filename
    $parts = explode('/', $template_file_path);
    $template_file_name = array_pop($parts);

    $custom_directory = 'custom';
    $new_file = ROOTDIR . DIRECTORY_SEPARATOR . 'templates' . DIRECTORY_SEPARATOR . $custom_directory . DIRECTORY_SEPARATOR . $template_file_name;

    if (!file_exists($new_file)) {
        return $tpl_output;
    }

    $tpl_output = $smarty->fetch($new_file);

    return $tpl_output;
}

$new_file正确返回文件路径。

0 个答案:

没有答案