Child pages
  • Guide to Template Toolkit - API Calls from Template Toolkit
Skip to end of metadata
Go to start of metadata

 

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. For more information, read the  Template::Manual  documentation.

API calls

<!-- Call a UAPI function. -->
[% execute( 'Module', 'function', { 'parameter' => 'value', 'parameter' => 'value', 'parameter' => 'value', } ); %] 

Note:

For more information about UAPI calls, read our Guide to UAPI documentation. 

<!-- Call a cPanel API 2 function. -->
[% USE Api2; Api2.exec( 'Module', 'function', { 'parameter' => 'value', 'parameter' => 'value', 'parameter' => 'value', } ); %]

Note:

For more information about cPanel API 2 calls, read our Guide to cPanel API 2 documentation.


Warning:

cPanel API 1 is deprecated. We strongly recommend that you use cPanel API 2 or UAPI instead. 

<!-- 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.
  • For more information about cPanel API 1 calls, read our Guide to cPanel API 1 documentation.


These examples use the following variables:

VariableDescriptionPossible valuesExample
ModuleThe function's module.Any module in the specified API. Email
functionThe function name.Any function in the specified module.addpop
parametersThe function's input parameters.

Any parameter from the specified function.

domain
valueThe 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 the lists 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 and humandiskused 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