Custom Template PHP
On this page
If you want to include custom PHP logic in your customized templates, we recommend using hooks.
We plan to permanently remove support for legacy Smarty tags in WHMCS 9.0. You must disable and remove them.
Hook Points
Hook points for every page of the Client Area allow you to define system theme and order form template variables.
For a full list of available hooks, see our Developer Documentation.
Example Hook File
The following example demonstrates using a hook on the Client Area View Ticket page:
<?php
/**
* Hook sample for defining additional template variables
*
* @param array $vars Existing defined template variables
*
* @return array
*/
function hook_template_variables_example($vars)
{
$extraTemplateVariables = array();
// set a fixed value
$extraTemplateVariables['fixedValue'] = 'abc';
// fetch clients data if available
$clientsData = isset($vars['clientsdetails']) ? $vars['clientsdetails'] : null;
// determine if client is logged in
if (is_array($clientsData) && isset($clientsData['id'])) {
$userId = $clientsData['id'];
// perform calculation here
$extraTemplateVariables['userSpecificValue'] = '123';
$extraTemplateVariables['anotherUserOnlyValue'] = '456';
}
// return array of template variables to define
return $extraTemplateVariables;
}
add_hook('ClientAreaPageViewTicket', 1, 'hook_template_variables_example');
The hook code above defines the additional system theme and order form template {$fixedValue}
variable and, for an authenticated
user, the {$userSpecificValue}
and {$anotherUserOnlyValue}
variables.
You can them use them in the associated system theme and order form template file (in this example, viewticket.tpl
):
<p>The fixed value is {$fixedValue}.</p>
{if $userSpecificValue && $anotherUserOnlyValue}
<p>I also have this {$userSpecificValue} and {$anotherUserOnlyValue} to show you.</p>
{/if}
Last modified: October 29, 2024