Introduction
cPanel & WHM uses template files to construct interfaces that call cPanel's APIs. Template Toolkit files for cPanel & WHM templates use the same formatting as other Template Toolkit files.
API calls
UAPI
<!-- Call a UAPI function. -->
[% execute( 'Module', 'function', { 'parameter' => 'value', 'parameter' => 'value', 'parameter' => 'value', } ); %]
cPanel API 2
<!-- Call a cPanel API 2 function. -->
[% USE Api2; Api2.exec( 'Module', 'function', { 'parameter' => 'value', 'parameter' => 'value', 'parameter' => 'value', } ); %]
cPanel API 1
Warning:
cPanel API 1 is deprecated. We strongly recommend that you use cPanel API 2 or UAPI instead.
1
2
|
<!-- Call a cPanel API 1 function. --> [% USE Api1; Api1.exec( 'Module', 'function', { 'value', 'value', 'value', } ); %] |
Notes:
- cPanel API 1 calls use numbered, rather than named, parameters.
These examples use the following variables:
Variable |
Description |
Possible values |
Example |
Module |
The function's module. |
Any module in the specified API. |
|
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.
1
2
3
4
|
[% 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:
1
2
3
|
list@example.com - 17.2 KB admins@example.com - 1.7 MB curmudgeons@example.com - 47.4 GB |