{"templateId":"markdown","sharedDataIds":{"sidebar":"sidebar-sidebars.yaml"},"props":{"metadata":{"markdoc":{"tagList":["admonition"]},"type":"markdown"},"seo":{"title":"Using Hooks","description":"Developer documentation for the WHMCS API — the","llmstxt":{"hide":false,"sections":[{"title":"Table of contents","includeFiles":["**/*"],"excludeFiles":[]}],"excludeFiles":[]}},"dynamicMarkdocComponents":[],"compilationErrors":[],"ast":{"$$mdtype":"Tag","name":"article","attributes":{},"children":[{"$$mdtype":"Tag","name":"Heading","attributes":{"level":1,"id":"using-hooks","__idx":0},"children":["Using Hooks"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["We recommend that all custom PHP logic be performed via hooks. Hooks are the ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["only"]}," future-proof way of performing your own PHP logic at the time of page rendering."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["Historically, Smarty has allowed you to define custom PHP logic directly within system theme and order form template files. This has often been used by users and third party developers as a quick and convenient way of performing additional logic and defining additional system theme and order form template output."]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["However, as of Smarty 3, support for the {php} block has been removed, and we are only providing legacy support to ease the transition for developers and users who work with our platform and rely on this functionality."]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Info"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The exposure of the template object via the legacy variable ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["$template"]},", available within the deprecated PHP blocks context, is only available if ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["template_object"]}," is itemized in the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["enabled_special_smarty_vars"]}," array as described in our ",{"$$mdtype":"Tag","name":"MarkdownLink","attributes":{"href":"https://docs.whmcs.com/Smarty_Security_Policy#Supported_Policy_Settings_and_Values"},"children":["Smarty Security Policy"," "]}," documentation."]}]},{"$$mdtype":"Tag","name":"Heading","attributes":{"level":2,"id":"example","__idx":1},"children":["Example"]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The below example demonstrates how a hook can be used to perform additional PHP logic and define system theme and order form template variables for use in client area template files."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"<?php\n/**\n * Hook sample for defining additional template variables\n *\n * @param array $vars Existing defined template variables\n *\n * @return array\n */\nfunction hook_template_variables_example($vars)\n{\n    $extraTemplateVariables = array();\n\n    // set a fixed value\n    $extraTemplateVariables['fixedValue'] = 'abc';\n\n    // fetch clients data if available\n    $clientsData = isset($vars['clientsdetails']) ? $vars['clientsdetails'] : null;\n\n    // determine if client is logged in\n    if (is_array($clientsData) && isset($clientsData['id'])) {\n        $userId = $clientsData['id'];\n        // perform calculation here\n        $extraTemplateVariables['userSpecificValue'] = '123';\n        $extraTemplateVariables['anotherUserOnlyValue'] = '456';\n    }\n\n    // return array of template variables to define\n    return $extraTemplateVariables;\n}\n\nadd_hook('ClientAreaPageViewTicket', 1, 'hook_template_variables_example');\n"},"children":[]},{"$$mdtype":"Tag","name":"Admonition","attributes":{"type":"info","name":"Tip"},"children":[{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The example above executes on the ",{"$$mdtype":"Tag","name":"strong","attributes":{},"children":["View Ticket"]}," page within the client area. There are hook points available for every page of the WHMCS client area. They allow you to define template variables in this way. For a full list, see the Client Area Interface Hooks Index Listing."]}]},{"$$mdtype":"Tag","name":"p","attributes":{},"children":["The above hook defines the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{$fixedValue}"]}," template variable and, in the case of a logged in user, the ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{$userSpecificValue}"]}," and ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["{$anotherUserOnlyValue}"]}," variables. These can then be used inside the associated template file (in this case, ",{"$$mdtype":"Tag","name":"code","attributes":{},"children":["viewticket.tpl"]},") in the regular way."]},{"$$mdtype":"Tag","name":"CodeBlock","attributes":{"header":{"controls":{"copy":{}}},"source":"<p>The fixed value is {$fixedValue}.</p>\n\n{if $userSpecificValue && $anotherUserOnlyValue}\n    <p>I also have this {$userSpecificValue} and {$anotherUserOnlyValue} to show you.</p>\n{/if}\n"},"children":[]}]},"headings":[{"value":"Using Hooks","id":"using-hooks","depth":1},{"value":"Example","id":"example","depth":2}],"frontmatter":{"title":"PHP Logic","seo":{"title":"Using Hooks"}},"lastModified":"2026-08-03T17:00:42.000Z","pagePropGetterError":{"message":"","name":""}},"slug":"/themes/php","userData":{"isAuthenticated":false,"teams":["anonymous"]},"isPublic":true}