|
|
Line 1: |
Line 1: |
− | The basic template syntax can be seen by looking at the templates. Template files use regular HTML along with tags for where the WHMCS data is inserted into them. All pages have specific variables which you can use. A complete list of variables on a page is available by entering the following tag into the template:
| + | <div class="docs-alert-info"> |
− | | + | <span class="title">Note</span><br /> |
− | <div class="docs-alert-info"><center>'''{debug}'''</center></div> | + | This page has moved to [https://developers.whmcs.com/themes/variables/ https://developers.whmcs.com/themes/variables/] |
− | | + | </div> |
− | The next access to the page using that template file after adding this code will show a popup window. This window will show all the different variables which you can use on the page. Access variables using the {$variable} syntax.
| |
− | | |
− | ==Common Template Variables Available on All Pages==
| |
− | | |
− | The following is a list of template variables available for use in all the template files of WHMCS:
| |
− | | |
− | *{$BASE_PATH_CSS} - The base URL to common CSS assets.
| |
− | *{$BASE_PATH_FONTS} - The base URL to common font assets.
| |
− | *{$BASE_PATH_IMG} - The base URL to common image assets.
| |
− | *{$BASE_PATH_JS} - The base URL to common Javascript assets.
| |
− | *{$charset} - The configured character set.
| |
− | *{$client} - The currently logged in [http://docs.whmcs.com/classes/classes/WHMCS.User.Client.html Client], or ''null'' if a client is not logged in.
| |
− | *{$companyname} - The configured company name
| |
− | *{$date_day} - The current calendar day.
| |
− | *{$date_month} - The current calendar month.
| |
− | *{$date_year} - The current calendar year.
| |
− | *{filename} - The basename of the current file requested by the web browser.
| |
− | *{$language} - The name of the language to display to the user.
| |
− | *{$loggedin} - ''true'' or ''false'' depending on if a client is logged in.
| |
− | *{$logo} - The path to the configured logo image.
| |
− | *{$pagetitle} - The current page's title.
| |
− | *{$reCaptchaPublicKey} - The configured [https://www.google.com/recaptcha/intro/index.html reCAPTCHA] site key. This can be an empty string if the WHMCS installation does not use Google reCAPTCHA.
| |
− | *{$systemNonSSLURL} - The configured non-SSL URL.
| |
− | *{$systemsslurl} - The configured SSL URL.
| |
− | *{$systemurl} - The URL to the WHMCS system. Either the SSL or non-SSL URL depending on whether the current page loaded via HTTPS.
| |
− | *{$template} - The name of the template used for display.
| |
− | *{$todaysdate} - The current date, presented in "l, jS F Y" format.
| |
− | *{$token} - A [https://en.wikipedia.org/wiki/Cross-site_request_forgery CSRF] token to use on POST forms.
| |
− | *{$WEB_ROOT} - Your WHMCS system's base URL.
| |
− | | |
− | ===Custom Template Variables===
| |
− | The template parameters available in templates will vary depending upon the page/object being requested.
| |
− | | |
− | Should you require additional content or variables that are not defined by default, you can add to them using hooks. The following hooks are available for these purposes:
| |
− | | |
− | * Client Area: ''[[Hooks:ClientAreaPage]]''
| |
− | * Admin Area: ''[[Hooks:AdminAreaPage]]''
| |
− | * Email Messages: ''[[Hooks:EmailPreSend]]''
| |
− | | |
− | ==Displaying Text to Logged In Users Only==
| |
− | | |
− | To display something on the page only if a user is logged in, use the following syntax:
| |
− | <syntaxhighlight lang="smarty">
| |
− | {if $loggedin}
| |
− | <p>User is logged in so display client only information</p>
| |
− | {else}
| |
− | <p>User is not logged in so display this</p>
| |
− | {/if}
| |
− | </syntaxhighlight>
| |
− | | |
− | ==Displaying Text if Certain Conditions Are Met==
| |
− | | |
− | It can often be necessary to display text or messages when certain conditions are met. For example, you might want to add extra text output when iterating through products. (Or, payment gateways, or display card scheme logos associated with your merchant account, etc.). Achieve this by using the if statement syntax:
| |
− | | |
− | <syntaxhighlight lang="smarty">{if $gateway.name eq "PayPal"}We accept PayPal{/if}</syntaxhighlight>
| |
− | | |
− | This example would display the message "We accept PayPal" if that option is available on the checkout page. This can be used for any variable.
| |
− | | |
− | ==Translating Language Strings==
| |
− | | |
− | WHMCS provides the {lang} function for templates to present text in the user's language. Call it with the "key" parameter representing the key in the language to translate.
| |
− | | |
− | <syntaxhighlight lang="smarty">
| |
− | {**
| |
− | * Defined as $_LANG['forgotpw'] in language files:
| |
− | *
| |
− | * Display "<strong>Forgot Password?</strong>" in English
| |
− | * or "<strong>¿Perdiste la contraseña?</strong>" in Spanish.
| |
− | *}
| |
− | <strong>{lang key="forgotpw"}</strong>
| |
− | </syntaxhighlight>
| |
− | | |
− | Use dots (".") to concatenate nested language keys.
| |
− | | |
− | <syntaxhighlight lang="smarty">
| |
− | {**
| |
− | * Defined as $_LANG['clientHomePanels']['unpaidInvoices'] in language files:
| |
− | *
| |
− | * Display "<strong>Unpaid Invoices</strong>" in English
| |
− | * or "<strong>Facturas Pendientes</strong>" in Spanish.
| |
− | *}
| |
− | <strong>{lang key="clientHomePanels.unpaidInvoices"}</strong>
| |
− | </syntaxhighlight>
| |
− | | |
− | Some language strings contain variable substitution. Variables for substitution begin with a colon (":"). Declare those variables and their values as parameters to the '''{lang}''' function:
| |
− | | |
− | <syntaxhighlight lang="smarty">
| |
− | {**
| |
− | * Defined as $_LANG['clientHomePanels']['creditBalance'] in language files:
| |
− | *
| |
− | * Display "<p>You have a credit balance of $100.00.</p>" in English
| |
− | * or "<p>Usted tiene un saldo acreedor de $100.00.</p>" in Spanish.
| |
− | *}
| |
− | <p>{lang key="clientHomePanels.creditBalance" creditBalance="$100"}</p>
| |
− | </syntaxhighlight>
| |
− | | |
− | ==Using {include_php} Syntax==
| |
− | If your template invokes & includes a PHP script by using the Smarty {include_php} syntax, the full path to the directory containing that script will need to be whitelisted in the 'trusted_dir' setting of your Policy.
| |
− | | |
− | For more information please refer to [[Smarty Security Policy|Smarty Security Policy]] section.
| |
− | | |
− | ==More Information==
| |
− | | |
− | For further documentation on template customisations, see the official Smarty 3 documentation @ http://www.smarty.net/docs/en/
| |
− | | |
− | {{Developer_Links}}
| |