我在开发人员文档中找不到它,但它确实暗示了这样一个事实,即在admin插件模块的_output函数中,我可以调用模板文件。
我该怎么做?我想调用一个模板文件从模块目录的最终输出显示我的内容在。
WHMCS v5.1.2。
如果我们在插件模块中使用get_defined_constants()
,我们看到,例如:
[SMARTY_DIR] => /var/www/vhosts/domain.com/httpdocs/whmcs/includes/smarty/
[SMARTY_CORE_DIR] => /var/www/vhosts/domain.com/httpdocs/whmcs/includes/smarty/internals/
[SMARTY_PHP_PASSTHRU] => 0
[SMARTY_PHP_QUOTE] => 1
[SMARTY_PHP_REMOVE] => 2
[SMARTY_PHP_ALLOW] => 3
意味着Smarty已经在管理区初始化了。剩下的就是创建我们的模板文件并包含它们(如果你想保持smarty的标准,在你的addon文件夹的templates
子目录中)。
修改_output
函数:
$smarty = new Smarty();
$smarty->assign('myvar', 'World');
$smarty->caching = false;
$smarty->compile_dir = $GLOBALS['templates_compiledir'];
$smarty->display(dirname(__FILE__) . '/templates/mytemplate.tpl');
剩下的就是你的模板文件mytemplate.tpl
的内容,但是你已经知道这部分了…
<p>Hello {$myvar}!</p>