'how to use smarty in WHMCS addon
I am trying to develop a addon for my WHMCS using the WHMCS API and smarty.
I have created the module and now on load I create the new $smarty instance and then try to load the template file that is in the addon_name/template directory but i am unable.
Below is my code and my errors:
WHMCS Output:
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');
?>
Error:
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
Solution 1:[1]
Is your path to template correct? I think you are missing public_html in template path
Solution 2:[2]
just use the FILE magic constant.
$smarty = new Smarty();
$smarty->assign('params1', $params);
$smarty->caching = false;
$smarty->compile_dir = $GLOBALS['templates_compiledir'];
$smarty->display(dirname(__FILE__) . '/template/statement_generator.tpl');
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Aamir Sarwar |
| Solution 2 | Ali Yazdanifar |
