stef_dotcom Posted January 29, 2016 Share Posted January 29, 2016 Hi, I'm trying to replace any php code in my templates to turn off the 'Allow PHP tags' setting to future proof our system but I am really struggling with moving everything to action hooks. Despite having read and re-read every bit of documentation I can find and adapting any examples I still can't get it to create a couple of simple variables which can then be used in the template header.tpl. I need to grab the url and work out which version of the site it is (dev, test or live) and add this to the beginning of the page title just to differentiate between the 3. I grabbed the following from one of the examples i found but the return just print 'Array' at the top of the page and nothing seems to be loaded into any variables: function prepend_header($vars) { $extraTemplateVariables = array(); $extraTemplateVariables['mode'] = 'live'; $extraTemplateVariables['titlemode'] = ''; $h = "<GETTING URL HERE>"; if ($h) { if (strlen($h)>5) { if (substr($h,0,4) == "dev.") { $extraTemplateVariables['titlemode'] = "DEVELOPMENT - "; $extraTemplateVariables['mode'] = 'dev'; } if (substr($h,0,5) == "test.") { $extraTemplateVariables['titlemode'] = "TEST - "; $extraTemplateVariables['mode'] = 'test'; } } } return $extraTemplateVariables; add_hook("ClientAreaHeaderOutput",1,"prepend_header"); Have also tried ClientAreaHeadOutput although I'm not sure what the difference is and it was no better. Any help gratefully received or better ways of doing this, thank you. I have a couple of other places where I need to do something similar so even just a better simple example of how to create a variable in an action hook that can be used in a template would be great, thanks again. 0 Quote Link to comment Share on other sites More sharing options...
adilmukarram Posted January 29, 2016 Share Posted January 29, 2016 Hi You has to return html rather than array like return '<meta name="'.$extraTemplateVariables['mode'].'" content="'.$extraTemplateVariables['mode'].'">'; 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 29, 2016 Share Posted January 29, 2016 try using the ClientAreaPage hook instead... <?php function prepend_header($vars) { $mode = 'live'; $titlemode = ''; $h = "<GETTING URL HERE>"; if ($h) { if (strlen($h)>5) { if (substr($h,0,4) == "dev.") { $titlemode = "DEVELOPMENT - "; $mode = 'dev'; } if (substr($h,0,5) == "test.") { $titlemode = "TEST - "; $mode = 'test'; } } } $extraTemplateVariables = array("mode" => $mode, "titlemode" => $titlemode); return $extraTemplateVariables; } add_hook("ClientAreaPage",1,"prepend_header"); that will create two new Smarty variables, {$mode} and {$titlemode} (names taken from the text in the quotes), and make them available to the client area pages - you could then modify header.tpl to use them. 0 Quote Link to comment Share on other sites More sharing options...
stef_dotcom Posted January 29, 2016 Author Share Posted January 29, 2016 Thanks very much for the replies, I'll give it a go... 0 Quote Link to comment Share on other sites More sharing options...
stef_dotcom Posted January 29, 2016 Author Share Posted January 29, 2016 Thanks again, working much better now, can I just ask so I know for next time - was the difference that ClientAreaHeaderOutput only returns html but ClientAreaPage can return anything or was it just that I was doing the whole thing wrong? Cheers 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted January 29, 2016 Share Posted January 29, 2016 also I think that Output hooks are used to add new sections of code, not to modify header code already defined in the template... btw - the link below shows how to use an action hook to modify $pagetitle - that should allow you to do what you want to do, without the need to edit header.tpl http://forum.whmcs.com/showthread.php?101427-Set-title-of-page-using-an-action-hook&p=420418#post420418 you'd just need to do your calculation and then concatenate dev/test etc with the pagetitle and output it back to $pagetitle. I think if you had to, you could do this without a hook and just do it in Smarty, but using the hook would be simpler.. if for no other reason that you won't have to modify the templates after every WHMCS update. 0 Quote Link to comment Share on other sites More sharing options...
stef_dotcom Posted January 29, 2016 Author Share Posted January 29, 2016 Ah yes, that looks even better - thanks a lot brian! 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.