如何在WHMCS插件中使用smarty


how to use smarty in WHMCS addon

我正在尝试使用WHMCS API和smarty为我的WHMCS开发一个插件。

我已经创建了模块,现在加载时我创建了新的$smarty实例,然后尝试加载addon_name/template目录中的模板文件,但我无法加载。

以下是我的代码和错误:

WHMCS输出:

function statement_generator_output($vars) {
      include('mainform.php');
}

Mainform.php:

<?
require_once '/home/account/public_html/hosting/vendor/smarty/smarty/libs/Smarty.class.php';
$smarty = new Smarty;
//$smarty->force_compile = true;
$smarty->debugging = true;
$smarty->caching = false;
$smarty->cache_lifetime = 120;
$smarty->assign("action", 'hello');
$smarty->display('/home/account/hosting/modules/addons/statement_generator/template/statement_generator.tpl');
?>

错误:

Fatal error: Uncaught --> Smarty: Unable to load template file '/home/account/hosting/modules/addons/statement_generator/template/statement_generator.tpl' <-- thrown in /home/account/public_html/hosting/includes/classes/WHMCS/Terminus.php on line 0

您的模板路径是否正确?我认为您在模板路径

中缺少public_html

只需使用FILE魔术常量。

$smarty = new Smarty();
        $smarty->assign('params1', $params);
        $smarty->caching = false;
        $smarty->compile_dir = $GLOBALS['templates_compiledir'];
        $smarty->display(dirname(__FILE__) . '/template/statement_generator.tpl');