How to Create a Custom Page for WHMCS?

First, we need to create an a.php file by following the steps

Create a PHP file

> Please login to your cPanel account

> Please go to the file manager

> Please go to the WHMCS root directory

> Please click on the File button.

> Please enter the name of the file in the pop-up 

> Please click the Create New File button.

Add PHP code

> Please go to the File Manager

> Please Navigate to your WHMCS root directory

> Please open the .php file you created in the previous section you can right-click on it, then click on Edit 

> Please copy and paste the following code to the file



<!--?php

use WHMCS\ClientArea;
use WHMCS\Database\Capsule;

define('CLIENTAREA', true);

require __DIR__ . '/init.php';

$ca = new ClientArea();

$ca--->setPageTitle('Your Page Title Goes Here');

$ca->addToBreadCrumb('index.php', Lang::trans('globalsystemname'));
$ca->addToBreadCrumb('mypage.php', 'Your Custom Page Name');

$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);

// Check login status
if ($ca->isLoggedIn()) {

/**
* User is logged in - put any code you like here
*
* Here's an example to get the currently logged in clients first name
*/

$clientName = Capsule::table('tblclients')
->where('id', '=', $ca->getUserID())->pluck('firstname');
// 'pluck' was renamed within WHMCS 7.0. Replace it with 'value' instead.
// ->where('id', '=', $ca->getUserID())->value('firstname');
$ca->assign('clientname', $clientName);

} else {

// User is not logged in
$ca->assign('clientname', 'Random User');

}

/**
* Set a context for sidebars
*
* @link https://docs.whmcs.com/Editing_Client_Area_Menus#Context
*/
Menu::addContext();

/**
* Setup the primary and secondary sidebars
*
* @link https://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('mypage');

$ca->output();

 

 

> Please click on the save changes button

 

Now please create a TPL file to save the HTML by following the steps below

> Please login to your cPanel account

> Please click the file manager

> Please go to the following directory inside of your WHMCS root directory templates/name-of-template//

> Please click on the file button

> Please enter the file name like abc.tpl

> Please click on the create new file button

 

ADD HTML

> Please right-click on the .tpl file you created and select Edit

> Please enter the HTML like the below example

 

<h3>This is my custom WHMCS page's content</h3>

<p>I used the code found <a href="https://developers.whmcs.com/advanced/creating-pages/" target="_blank" title="Click here to navigate to WHMCS Support to obtain the code needed for creating a custom page.">here</a>.</p>

<p>I put that code into a file named: </p>

<p><code>mypage.php</code>, which resides in the root directory (where my WHMCS is installed).</p>

<p>Now, I can write HTML into the file named:</p>

<p><code>mypage.tpl</code>, located in the templates/six/ directory. Any HTML I save into that file, will be displayed on my new custom page.</p>

 

> Please click on the save changes button

 

 

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to Access MailServer Configuration Options?

> Please login to your WHM account > Please Search for “mailserver”  > Please click on...

How to Switch Mailserver Between Mdbox and Maildir in WHM?

> Please login to your cPanel account > Please search for the “mailbox” in the search box...

How to configure the exim settings with the basic editor?

> Please login to your WHM account > Please search with “exim” in the search box >...

How to configure the exim settings with the Advance editor?

> Please login to your WHM account > Please search with  “exim” in the serch box >...

How to Backup Exim Configuration?

> Please login to your WHM account > Please search “exim” in the search box > Please...

Powered by WHMCompleteSolution