Version 6 Template Migration Guide

From WHMCS Documentation

WHMCS 6 includes an internal upgrade from Smarty 2 to Smarty 3.1. As a result, you will need to update any custom templates that use Smarty 2 features that are not available in Smarty 3.

{literal} Changes

Smarty 3 changes the way in which templates interpret whitespace, removing the need for {literal} tags around { and } characters in CSS and JavaScript blocks.

For example:

<script type="text/javascript">
    function example()
    {literal}{{/literal}
        alert('example');
    {literal}}{/literal}
</script>

Converts to:

<script type="text/javascript">
    function example()
    {
        alert('example');
    }
</script>

{php} Block Syntax

We deprecated legacy Smarty tags in WHMCS 6.0 and will remove support entirely in WHMCS 9.0. You must remove these tags from your custom themes and templates. For more information, see Eliminating Legacy Smarty Tags.

In most cases, you can update a template's {php} block to a hook file. Hooks perform custom actions at specific points in WHMCS's page generation routines.

For example, you can reference existing template variables or define new template variables in a PHP file in the includes/hooks directory. Inspect and assign variables using the ClientAreaPage hook:

add_hook('ClientAreaPage', 1, function($templateVariables)
{
    // Look for an existing template variable.
    foreach ($templateVariables as $name => $variable) {
        doThings();
    }
     
    // Define new variables to send to the template.
    return array(
        'myCustomVariable' => 'myCustomValue',
    );
});

Then, reference the newly-assigned variable in the template:

<p>My custom variable value is: {$myCustomVariable}.</p>

For more information on using hooks in templates, see Templates and Custom PHP Logic.

The $client Object

All Client Area templates have a $client variable that represents the authenticated client. $client is either a WHMCS\Client\User object or null if no client is authenticated.

{if $client === null}
    <p>Nobody is logged in. :(</p>
{else}
    <p>Hello, {$client->firstName} {$client->lastName}!</p>
{/if}

For more information, see Using Models.