If we use get_defined_constants()
in our addon module we see, for example:
[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
Meaning Smarty is already initialised in the admin area. All that's left is to create our template files and include them (in a templates
subdir in your addon folder if you want to keep to a smarty standard).
Modify the following for your _output
function:
$smarty = new Smarty();
$smarty->assign('myvar', 'World');
$smarty->caching = false;
$smarty->compile_dir = $GLOBALS['templates_compiledir'];
$smarty->display(dirname(__FILE__) . '/templates/mytemplate.tpl');
All that's left is the contents of your template file mytemplate.tpl
, but you know this part already...
<p>Hello {$myvar}!</p>