Jump to content

Simplified Custom Pages


leemason

Recommended Posts

Ive had WHMCS installed for quite a while now and have found it easiest after trying to intergrate with wordpress/joomla, or using the CMS addon to use custom page templates.

 

It might not be for everyone but for me it works great. The only issue i have to overcome was how longwinded getting a custom page was. I found a solution!!!1

 

(for me it may work for you it may not im just letting you all know what i did incase it can help you too.)

 

 

let go over how you create custom pages for whmcs:

 

create a php file in the root for examples sake hosting_features.php

 

Then add the code provided by WHMCS which will add pagetitle, other vars, etc and send it to a template file.

 

then create the template file.

 

This isnt so hard, its just time consuming and has to be done for every single page, so you end up with double the amount of files as pages (one php file, one tpl file).

 

 

here is my solution

 

1 php file for all custom pages

 

1 template file for each custom page

 

and here is how i did it:

 

 

create a file called page.php (file can be called anything but remember this will be part of you url)

 

add this code below:

 

<?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");
# 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
}

if(isset($p)){
$page = $p;

$p = str_replace("_"," ", $p);

$pagetitle = $_LANG['$p'];

$breadcrumbnav = '<a href="index.php">'.$_LANG['globalsystemname'].'</a>';

$breadcrumbnav .= ' > <a href="new_page.php">'.$p.'</a>'; 

initialiseClientArea($p,'',$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;

$smartyvalues["page"] = $page;

# Define the template filename to be used without the .tpl extension
$templatefile = 'std'; 
outputClientArea($templatefile);

}?>

 

* code has been compressed for viewing on forum

 

 

Okay this is very similar to the current setup you would use for setting up a custom page, but adds extra functionality and uses get variables.

 

The key areas are:

 

if(isset($p)){
$page = $p;

$p = str_replace("_"," ", $p);

$pagetitle = $_LANG['$p'];

 

this get the variable ?p= from the url, strips the denominators chosen (you could use "-" instead if you wanted) and sets up the page title

 

so if you url said page.php?p=Testing_Custom_Page

 

you page title would be Testing Custom Page

 

 

the next key area is this:

 

$smartyvalues["page"] = $page;

# Define the template filename to be used without the .tpl extension
$templatefile = 'std'; 
outputClientArea($templatefile);

 

We set a smarty variable called $page using the original get variable (which includes the underscores) and then setup the page to run the "std" template file.

 

 

the next thing to do is create the "std.tpl" file in your current theme. and add this code:

 

{if file_exists("/home/username/public_html/whmcsfolder/templates/templatename/pages/$page.tpl") }
{include file="/home/username/public_html/whmcsfolder/templates/templatename/pages//$page.tpl"}
{else}
<h2 style="text-align:center;margin:40px 0px;">Page Not Found</h2>
<p style="text-align:center">It appears the page your are looking for does not exist. If you found this page in one of our naviagtion links please <a href="contact">contact us</a> so we can rectify the issue.</p>
{/if}

 

this uses the variable $page we setup earlier and checks if a file called $page.tpl exists, and if it does includes the file, if it doesnt it will display 404 information.

 

Notice the template file searches in a sub folder called "pages" in the current theme. i do this to make organisation easier for me so all custom pages are together and seperate from core template files.

 

 

Now all you have to do is create your pages, if you want a page called "This mod is great" simply create a .tpl file called "This_mod_is_great.tpl" and put it in the custom pages folder.

 

then all you have to do is link to it like this:

 

page.php?p=This_mod_is_great

 

 

no extra work for unlimited custom pages.

 

 

 

And then for the SEO guys out there lets neaten the url up a bit.

 

add this to you .htaccess file AFTER the line saying "RewriteEngine On":

 

RewriteRule ^page/([^/]+) /page.php?p=$1 [NC]

 

 

now you access your custom pages by the url:

 

yourdomain.com/page/Page_Title

 

 

hope this helps someone out, and let me know if you think you can improve it.

 

 

PPS: you can add as many template variables as you want using the get variables, simple add the same code as you see in the page.php where it says:

 

$smartyvalues["page"] = $page;

 

and copy paste it with the new variable, ie:

 

 

$smartyvalues["newpagevariable"] = $newpagevariable;

 

and then on you urls simple append:

 

&newpagevariable=something

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated