Jump to content

Help with WHMCS - Smarty php tags now have to be hooks?

Recommended Posts

I am looking to update whmcs from 5.3.x to 6 however some of my template files contain {php} tags...


I tried enabling the legacy php tag support within whmcs but it doesn't help - none of the php tags are parsed on a test copy of the site.


I have found this article which suggests the php code needs to be loaded through a hook http://docs.whmcs.com/Templates_and_Custom_PHP_Logic, but I can't quite grasp what is required to get it working.


Heres an example.. if someone can explain how this would work within a hook I think I can figure the rest out on my own!


if( $qrystr = strpos( $_SERVER['REQUEST_URI'], '?' ) ) $url = substr( $_SERVER['REQUEST_URI'], 0, $qrystr ); elseif( $qrystr = strpos( $_SERVER['REQUEST_URI'], '#' ) ) $url = substr( $_SERVER['REQUEST_URI'], 0, $qrystr ); else $url = $_SERVER['REQUEST_URI'];
$titleprefix = "Title";
$titledefault = "$titleprefix - blah blah blah";
$title["/affiliates.php"]="$titleprefix - Affiliates";



and so on.... for each page.

and there are further lines for other functions like setting meta tags and robots prefs, but they are the same format as above..


Thanks for any help!

Share this post

Link to post
Share on other sites

Looking at the code you provided, what you linked to and this page http://docs.whmcs.com/Hooks I think I know what you're wanting.


You need to move the code you have within {php}{/php} into a function and then using add_hook define when that function should be called so that you may access it's information in the template file.

function hook_template_variables_example($vars) {

    if( $qrystr = strpos( $_SERVER['REQUEST_URI'], '?' ) ) 
        $url = substr( $_SERVER['REQUEST_URI'], 0, $qrystr ); 
    elseif( $qrystr = strpos( $_SERVER['REQUEST_URI'], '#' ) ) 
        $url = substr( $_SERVER['REQUEST_URI'], 0, $qrystr ); 
        $url = $_SERVER['REQUEST_URI'];
    $prefix = "Title";
    $default = "$prefix - blah blah blah";

    $extraTemplateVariables = array(
        'title_url' = $default,
        'title_root' = $default,
        'title_index' = $default,
        'title_affiliates' = $prefix . " - Affiliates",
    return $extraTemplateVariables;
add_hook('ClientAreaPageViewTicket', 1, 'hook_template_variables_example');

That is what I came up with using the code you provided. It is attaching itself to the Hook Point ClientAreaPageViewTicket which according to that page says Runs when the View Ticket page is displayed.


From within the template file itself, because the hook is called and it returned that array of variables, I can now access the data by calling {$title_url} or {$title_root} or {$title_index} or {$title_affiliates}


None of this is tested, I don't have whmcs and I'm just going on what the documentation leads me to believe.

Share this post

Link to post
Share on other sites

Thanks for your reply. That seems to return the following error: Parse error: syntax error, unexpected '=', expecting ')' in /home/galaxy/public_html/includes/hooks/header.php on line 16


Also I'm not quite sure the logic is correct, the idea is to put something like this in the title tags on the header file i.e. <title>{$pagetitle}</title>, obviously the {$pagetitle} bit would come from the hook, which would contain a list of page titles for each page, it does mean i have a list of variables for each page title, but theres only 20 or so, so its not too bad.





Share this post

Link to post
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.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.