In the WHMCS Templates all of the pages come pre-made. However, if you decide to create custom pages you may find it useful to know how to display content on specific pages such as those you create. Generally this would be used within files that by default are used for every page of the template such as the header.tpl and footer.tpl files. By targeting specific pages it allows you to add content to the header/footer and control which pages it does and does not display on.
In this tutorial we will show you how this can be achieved.
Targeting Options
Within WHMCS we can use pre-defined variables to detect which page the user is on. Here at Zomex we make use of 2 variables:
$filename - This variable is the name of the PHP filename used by the page. e.g company.php = company
$templatefile - This variable is the name of the TPL filename used by the page. e.g company.tpl = company
Both can be used to target pages but using templatefile tends to be more specific for pages that use the same URL multiple times (e.g index.php?page=example). Some recommended uses are:
Homepage - To target the homepage use $templatefile eq "homepage"
Login - To target the login page use $templatefile eq "login"
Client Area - To target the clientarea as a whole (clientarea.php) page use $filename eq "clientarea"
Register - To target the register page use $filename eq "register"
Code Examples
Listed below are some useful code examples.
A Single Page
{if $filename eq "company"}
show content on company.php
{/if}
A Single Page With Fallback (Else)
{if $filename eq "company"}
show content on company.php
{else}
show content on all other pages
{/if}
The Same Content/Code On A Selection Of Pages
{if $filename eq "company" or $filename eq "web-hosting" or $templatefile eq "homepage"}
show content on company.php, web-hosting.php & index.php
{/if}
Different Content/Code On A Selection Of Pages
{if $templatefile "homepage"}
show content on index.php
{elseif $filename eq "web-hosting"}
show content on web-hosting.php
{elseif $filename eq "company"}
show content on company.php
{else}
show content on all other pages (or remove this line of text for no display)
{/if}
Show On All Pages Apart From
{if $filename neq "company"}
show on all pages apart from company.php
{/if}
Request Support
We hope you found this documentation useful. If you run into any issues we will be happy to assist you.