Reputation: 2349
I can't find it anywhere in the developer documentation but it does hint to the fact that in the _output function of an admin addon module I can call a template file.
How do I do this? I would like to call a template file for final output from the module directory to display my content in.
WHMCS v5.1.2 by the way.
Upvotes: 4
Views: 2531
Reputation: 314
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>
Upvotes: 5