Development Guides Home >> Guide to Template Toolkit
Guide to Template Toolkit - API Calls from Template Toolkit
Introduction
cPanel & WHM uses template files to construct interfaces that call cPanel's API functions. Template Toolkit files for cPanel & WHM templates use the same formatting as other Template Toolkit files. For more information, read the Template::Manual documentation.
- You cannot use Template Toolkit files to call WHM API 1 functions.
- If you use Template Toolkit files in a WHM plugin, you must add the function in a Perl script. For more information, read our Guide to WHM Plugins documentation.
API calls
Enter these API functions in the Template Toolkit file format.
UAPI
[% execute( 'Module', 'function', { 'parameter' => 'value', 'parameter' => 'value', 'parameter' => 'value', } ); %]
For more information about UAPI calls, read our UAPI documentation.
cPanel API 2
[% USE Api2; Api2.exec( 'Module', 'function', { 'parameter' => 'value', 'parameter' => 'value', 'parameter' => 'value', } ); %]
For more information about cPanel API 2 calls, read our cPanel API 2 documentation.
cPanel API 1
cPanel API 1 is deprecated. We strongly recommend that you use cPanel API 2 or UAPI instead.
[% USE Api1; Api1.exec( 'Module', 'function', { 'value', 'value', 'value', } ); %]
- cPanel API 1 calls use numbered, rather than named, parameters.
- For more information about cPanel API 1 calls, read our Guide to cPanel API 1 documentation.
These examples use the following variables:
Variable | Description | Possible values | Example |
---|---|---|---|
Module |
The function's module. | Any module in the specified API. | Email |
function |
The function name. | Any function in the specified module. | addpop |
parameters |
The function's input parameters. | Any parameter from the specified function. | domain |
value |
The values to assign to the input parameter. | Parameters accept a variety of values. | example.com |
Example
The following example code calls UAPI's Email::list_lists
function.
[% lists = execute('Email', 'list_lists', { 'domain' => 'example.com' }) %]
[% FOREACH q = lists.data %]
<p> [% q.list %] - [% q.humandiskused %] </p>
[% END %]
-
Line 1 calls UAPI's
Email::list_lists
function and returns the data to thelists
variable. - Line 2 sets up a loop that repeats for each entry in the function's output.
-
Line 3 returns text in paragraph tags. The template will replace the variables with the values from the function's
list
andhumandiskused
output parameters. -
Line 4 ends the loop when the template has returned a line for each
list
in the function's output.
In the interface, this template code could display the following results:
list@example.com - 17.2 KB
admins@example.com - 1.7 MB
curmudgeons@example.com - 47.4 GB