Difference between revisions of "Creating Pages"

From WHMCS Documentation

Line 1: Line 1:
To add your own pages to the WHMCS system which utilise the WHMCS templating system, you may use the following code.  This code is designed to work with files placed in the root whmcs directory. This is ideal for adding custom pages to the client area or building an entire site around your WHMCS system.
+
Creating your own custom pages for WHMCS is simple. You can use this to extend the client area, for example building your whole site around WHMCS, or creating custom pages to provide additional functionality to your clients.
 
 
Create a new file using your favourite text editor such as notepad, copy and paste the following code into it:
 
  
 +
To get started, simply copy & paste the code below into a new PHP file and save it in the main WHMCS directory.
  
 
  <?php
 
  <?php
 
   
 
   
 
  define("CLIENTAREA",true);
 
  define("CLIENTAREA",true);
 +
//define("FORCESSL",true); # Uncomment to force the page to use https://
 
   
 
   
 
  require("dbconnect.php");
 
  require("dbconnect.php");
Line 13: Line 13:
 
   
 
   
 
  $pagetitle = $_LANG['clientareatitle'];
 
  $pagetitle = $_LANG['clientareatitle'];
$pageicon = "images/support/clientarea.gif";
 
 
  $breadcrumbnav = '<a href="index.php">'.$_LANG['globalsystemname'].'</a>';
 
  $breadcrumbnav = '<a href="index.php">'.$_LANG['globalsystemname'].'</a>';
 
  $breadcrumbnav .= ' > <a href="mypage.php">My Page</a>';  
 
  $breadcrumbnav .= ' > <a href="mypage.php">My Page</a>';  
 
   
 
   
  initialiseClientArea($pagetitle,$pageicon,$breadcrumbnav);
+
  initialiseClientArea($pagetitle,'',$breadcrumbnav);
 +
 +
# To assign variables to the template system use the following syntax.
 +
# These can then be referenced using {$variablename} in the template.
 +
 +
$smartyvalues["variablename"] = $value;  
 
   
 
   
 +
# Check login status
 
  if ($_SESSION['uid']) {
 
  if ($_SESSION['uid']) {
  # User is Logged In - put any code you like here
 
}
 
 
   
 
   
# To assign variables in Smarty use the following syntax.
+
  # User is logged in - put any code you like here
# This can then be used as {$variablename} in the template
 
 
   
 
   
  $smartyvalues["variablename"] = $value;  
+
  # Here's an example to get the currently logged in clients first name
 +
   
 +
  $result = mysql_query("SELECT firstname FROM tblclients WHERE id=".(int)$_SESSION['uid']);
 +
  $data = mysql_fetch_array($result);
 +
  $clientname = $data[0];
 +
  $smartyvalues["clientname"] = $clientname;
 +
 +
} else {
 +
 +
  # User is not logged in
 +
 +
}
 
   
 
   
 
  # Define the template filename to be used without the .tpl extension
 
  # Define the template filename to be used without the .tpl extension
 
   
 
   
  $templatefile = "homepage";  
+
  $templatefile = "custompage";  
 
   
 
   
 
  outputClientArea($templatefile);
 
  outputClientArea($templatefile);
Line 36: Line 49:
 
  ?>
 
  ?>
  
 +
This example above shows you the required layout of a custom page.  It demonstrates:
  
Edit $breadcrumbnav and  $templatefile to match the filename of the page you want to create. Eg. If you were creating a page called aboutus, you would edit  $templatefile = "homepage"; to $templatefile = "aboutus";. Save this as a php file and upload to your root WHMCS directory (eg. example.com/whmcs)
+
*How to initiate the page
 
+
*How to force the page to use SSL (FORCESSL)
 
+
*How to reference the language file variables ($_LANG)
Now create another text file, this is your template file and will contain the actual content for your custom page. Save this as a tpl file and upload to your templates directory (eg. example.com/whmcs/templates/*TEMPLATE NAME*).
+
*How to check if a user is logged in ($_SESSION['uid'])
 
+
*How to define template variables ($templatevars)
 
+
*And how to set the template to use and then output it
  
 +
The template file you define should be a filename in your active WHMCS system template folder, so for the example above the path would be /templates/default/custompage.tpl
  
To access your newly created custom page just visit the php file.
+
Now when you're ready to test, upload both the PHP and TPL file to the appropriate folders and then visit the PHP file in the root WHMCS directory to run.

Revision as of 13:55, 24 January 2011

Creating your own custom pages for WHMCS is simple. You can use this to extend the client area, for example building your whole site around WHMCS, or creating custom pages to provide additional functionality to your clients.

To get started, simply copy & paste the code below into a new PHP file and save it in the main WHMCS directory.

<?php

define("CLIENTAREA",true);
//define("FORCESSL",true); # Uncomment to force the page to use https://

require("dbconnect.php");
require("includes/functions.php");
require("includes/clientareafunctions.php");

$pagetitle = $_LANG['clientareatitle'];
$breadcrumbnav = '<a href="index.php">'.$_LANG['globalsystemname'].'</a>';
$breadcrumbnav .= ' > <a href="mypage.php">My Page</a>'; 

initialiseClientArea($pagetitle,,$breadcrumbnav);

# To assign variables to the template system use the following syntax.
# These can then be referenced using {$variablename} in the template.

$smartyvalues["variablename"] = $value; 

# Check login status
if ($_SESSION['uid']) {

  # User is logged in - put any code you like here

  # Here's an example to get the currently logged in clients first name

  $result = mysql_query("SELECT firstname FROM tblclients WHERE id=".(int)$_SESSION['uid']);
  $data = mysql_fetch_array($result);
  $clientname = $data[0];
  $smartyvalues["clientname"] = $clientname;

} else {

  # User is not logged in

}

# Define the template filename to be used without the .tpl extension

$templatefile = "custompage"; 

outputClientArea($templatefile);

?>

This example above shows you the required layout of a custom page. It demonstrates:

  • How to initiate the page
  • How to force the page to use SSL (FORCESSL)
  • How to reference the language file variables ($_LANG)
  • How to check if a user is logged in ($_SESSION['uid'])
  • How to define template variables ($templatevars)
  • And how to set the template to use and then output it

The template file you define should be a filename in your active WHMCS system template folder, so for the example above the path would be /templates/default/custompage.tpl

Now when you're ready to test, upload both the PHP and TPL file to the appropriate folders and then visit the PHP file in the root WHMCS directory to run.