Difference between revisions of "Working with Module Templates"

From WHMCS Documentation

(Created page with "Modules that provide user facing output typically use templates to define and control that output. There are some exceptions, most often in the case of older modules, but all...")
 
(Customising Templates)
 
(8 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Modules that provide user facing output typically use templates to define and control that output.  There are some exceptions, most often in the case of older modules, but all recent modules should be using templates.
+
[[Modules]] that provide user-facing output typically use templates to define and control that output.
 
+
   
==How Templates Work==
+
Module template files can exist in either the root directory of the module or in a <tt>templates</tt> subdirectory.
 
+
   
Module template files can exist in either the root directory of the module, or in a subfolder named "templates".
 
 
 
In addition, modules can ship with template files that are designed for specific templates. For example, in the case of the Licensing Addon module that we ship with WHMCS, we provide two templates, /modules/servers/licensing/templates/managelicense.tpl which is optimised and designed for Version 6 and specifically the six template and custom templates based on that.  But in addition, we also provide a /modules/servers/licensing/templates/five/managelicense.tpl template file which is optimised and designed for the Version 5 "five" template.
 
 
 
If your custom theme is based on the five template, you would likely want to consider using the overrides system below to have your custom template define the version optimised for five is used.
 
 
 
 
==Customising Templates==
 
==Customising Templates==
 +
 +
<div class="docs-alert-warning">
 +
<span class="title">WHMCS 6.0</span><br />
 +
We introduced this in WHMCS 6.0.
 +
</div>
 +
 +
You can customize module templates using an overrides system that allows customisations within your active Client Area theme directory. We recommend this for several reasons:
 +
 +
* Customizations remain unaffected through upgrades.
 +
* All of your customisations remain in a centralized location.
 +
* Customizations of module templates are portable with themes.
 +
* Backing up customizations is easier.
 +
 +
To create an override template, make a copy of the original template file within the following directory structure inside your custom template:
 +
 +
<div class="source-cli">/templates/yourtemplatename/modules/moduletype/modulename/</div>
 +
 +
For example, in the case of the <tt>cpanel</tt> provisioning module, you could customize <tt>/modules/servers/cpanel/templates/overview.tpl</tt> by creating the following template file:
 +
 +
<div class="source-cli">/templates/yourtemplatename/modules/servers/cpanel/overview.tpl</div>
 +
 +
Another example, this time based upon the <tt>licensing</tt> provisioning module, you can customize <tt>/modules/servers/licensing/templates/managelicense.tpl</tt> by creating the following template file:
 +
 +
<div class="source-cli">/templates/yourtemplatename/modules/servers/licensing/managelicense.tpl</div>
 +
 +
This also applies to addon modules. For example, you can customize the Client Area view template in <tt>/modules/addons/project_management/templates/clientview.tpl</tt> by creating this template file:
 +
 +
<div class="source-cli">/templates/yourtemplatename/modules/addons/project_management/clientview.tpl</div>
  
Module templates can be customised using an overrides system that allows customisations to be performed within your active client area template theme folder.
+
==Version-Specific Templates==
 
+
<div class="docs-alert-info">'''Recommended''' This functionality was introduced in WHMCS 6.0 and is present in 6.0.0-rc.1 and later.</div>
+
Modules can also provide templates that work with specific Client Area themes.
 
+
The advantages of customising module templates this way is that your customisations remain unaffected through upgrades, and all of your customisations become portable and possible to backup as part of your custom template folder.
+
In WHMCS 8.1 and higher, for example, there are two themes included by default: Twenty-One and Six. Six implements the Bootstrap 3 framework, while Twenty-One uses Bootstrap 4. Because of differences in how they apply styling and structures, a template that works for one may not work for the other. Because of this, WHMCS supports Version Specific Templates.
 
+
To create an override template, simply make a copy of the original template file within the following folder structure inside your custom template: ''/templates/yourtemplatename/modules/moduletype/modulename/''.
+
This allows you to define a default template that has additional templates to use in conjunction with specific system themes. For example, this could provide an older Bootstrap 3-compatible template for use with Six. For more information, see our [https://developers.whmcs.com/themes/ Developer Documentation on Themes].
 
 
For example, in the case of the provisioning module "cpanel", ''/modules/servers/cpanel/overview.tpl'' could be customised by creating the following template file: ''/templates/yourtemplatename/modules/servers/cpanel/overview.tpl''
 
 
 
Another example, this time based upon the provisioning module "licensing", ''/modules/servers/licensing/templates/managelicense.tpl'' can be customised by creating the following template file ''/templates/yourtemplatename/modules/servers/licensing/managelicense.tpl''
 
 
 
The same thing applies to addon modules too.  For example the client area view template located in ''/modules/addons/project_management/templates/clientview.tpl''' could be customised by creating the template file ''/templates/yourtemplatename/modules/project_management/templates/clientview.tpl''.
 

Latest revision as of 10:01, 27 January 2022

Modules that provide user-facing output typically use templates to define and control that output.

Module template files can exist in either the root directory of the module or in a templates subdirectory.

Customising Templates

WHMCS 6.0
We introduced this in WHMCS 6.0.

You can customize module templates using an overrides system that allows customisations within your active Client Area theme directory. We recommend this for several reasons:

  • Customizations remain unaffected through upgrades.
  • All of your customisations remain in a centralized location.
  • Customizations of module templates are portable with themes.
  • Backing up customizations is easier.

To create an override template, make a copy of the original template file within the following directory structure inside your custom template:

/templates/yourtemplatename/modules/moduletype/modulename/

For example, in the case of the cpanel provisioning module, you could customize /modules/servers/cpanel/templates/overview.tpl by creating the following template file:

/templates/yourtemplatename/modules/servers/cpanel/overview.tpl

Another example, this time based upon the licensing provisioning module, you can customize /modules/servers/licensing/templates/managelicense.tpl by creating the following template file:

/templates/yourtemplatename/modules/servers/licensing/managelicense.tpl

This also applies to addon modules. For example, you can customize the Client Area view template in /modules/addons/project_management/templates/clientview.tpl by creating this template file:

/templates/yourtemplatename/modules/addons/project_management/clientview.tpl

Version-Specific Templates

Modules can also provide templates that work with specific Client Area themes.

In WHMCS 8.1 and higher, for example, there are two themes included by default: Twenty-One and Six. Six implements the Bootstrap 3 framework, while Twenty-One uses Bootstrap 4. Because of differences in how they apply styling and structures, a template that works for one may not work for the other. Because of this, WHMCS supports Version Specific Templates.

This allows you to define a default template that has additional templates to use in conjunction with specific system themes. For example, this could provide an older Bootstrap 3-compatible template for use with Six. For more information, see our Developer Documentation on Themes.