In this tutorial we will show you how to create custom pages in WHMCS. This guide will focus on our Premium WHMCS Themes but should work with any WHMCS template.
Creating a custom page
Create a new .php file in the root of WHMCS. I always recommend using the page title without spaces and capitations, in this example we will create a page named windows-hosting.php. This file needs to contain the following code (as provided by WHMCS):
<?php
use WHMCS\Authentication\CurrentUser;
use WHMCS\ClientArea;
use WHMCS\Database\Capsule;
define('CLIENTAREA', true);
require __DIR__ . '/init.php';
$ca = new ClientArea();
$ca->setPageTitle('Windows Hosting');
$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('windows-hosting.php', 'Windows Hosting');
$ca->initPage();
//$ca->requireLogin(); // Uncomment this line to require a login to access this page
// To assign variables to the template system use the following syntax.
// These can then be referenced using {$variablename} in the template.
//$ca->assign('variablename', $value);
$currentUser = new CurrentUser();
$authUser = $currentUser->user();
// Check login status
if ($authUser) {
/**
* User is logged in - put any code you like here
*
* Use the User model to access information about the authenticated User
*/
$ca->assign('userFullname', $authUser->fullName);
$selectedClient = $currentUser->client();
if ($selectedClient) {
/**
* If the authenticated User has selected a Client Account to manage,
* the model will be available - put any code you like here
*/
$ca->assign(
'clientInvoiceCount',
$selectedClient->invoices()->count()
);
}
} else {
// User is not logged in
$ca->assign('userFullname', 'Guest');
}
/**
* Set a context for sidebars
*
* @link http://docs.whmcs.com/Editing_Client_Area_Menus#Context
*/
//Menu::addContext();
/**
* Setup the primary and secondary sidebars
*
* @link http://docs.whmcs.com/Editing_Client_Area_Menus#Context
*/
//Menu::primarySidebar('announcementList');
//Menu::secondarySidebar('announcementList');
# Define the template filename to be used without the .tpl extension
$ca->setTemplate('windows-hosting');
$ca->output();
Note the Windows Hosting, windows-hosting.php and windows-hosting references. These should be changed based on the page you'd like to create.
Create the .tpl page
The last file to be created is a template file (.tpl), this will contain the content of your custom page. It needs to be named exactly in line 35 of the above code but with the .tpl extension. So in this case it is windows-hosting.tpl. This file needs to be created in the following directory:
/public_html/templates/YOUR_TEMPLATE/
Your new page can contain any HTML content you like, for example:
<h2>This is a page title</h2>
<p>This is a paragraph</p>
View the new page
The new page will now be viewable at:
yourdomain.com/windows-hosting.php
Developing Your New Page
Content needs to be added to the .tpl file of your custom page, this content can be in the form of HTML.
HTML Snippets
Your WHMCS Template comes with a wide selection of ready-made HTML Snippets allowing you to easily generate pre-integrated and fully responsive elements for your new pages. Elements include feature boxes, pricing tables, buttons & more.
Adding Your Page To The Menu
Now you have created your new page you may wish to add a link to it within the template. Click the button below for more information on how to do this.
Request Support
We hope you found this documentation useful. If you run into any issues we will be happy to assist you.