adixm Posted October 15, 2020 Share Posted October 15, 2020 Hello I tried to assign a new variable in php. After upgrade to whmcs 8 $template->assign is not available anymore. Quote Error: Call to a member function assign() on null in This is the code $services = "Testtt"; $template->assign('vari', $services); Thanks! 0 Quote Link to comment Share on other sites More sharing options...
WHMCS Support Manager WHMCS John Posted October 15, 2020 WHMCS Support Manager Share Posted October 15, 2020 Hi @adixm, Here are the relevant resources you'll need: https://docs.whmcs.com/Version_8.0.0_Release_Notes#Library_Updates https://developers.whmcs.com/advanced/upgrade-to-whmcs-8/ 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 16, 2020 Share Posted October 16, 2020 21 hours ago, adixm said: I tried to assign a new variable in php. if you're creating PHP pages and wanting to add variables in them, then the creating pages docs explains that you could use... $services = "Testtt"; $ca->assign('vari', $services); if you're using a hook, then you can just return the variable. ... and if you're in the Smarty template, you can assign a variable directly without any changes to the Smarty Security Policy - the shorthand way to do that would be... {assign vari "Testtt"} though there is a longer method as outline in the Smarty docs. 0 Quote Link to comment Share on other sites More sharing options...
heapmaster Posted October 30, 2020 Share Posted October 30, 2020 On 10/16/2020 at 7:46 AM, brian! said: if you're creating PHP pages and wanting to add variables in them, then the creating pages docs explains that you could use... $services = "Testtt"; $ca->assign('vari', $services); if you're using a hook, then you can just return the variable. ... and if you're in the Smarty template, you can assign a variable directly without any changes to the Smarty Security Policy - the shorthand way to do that would be... {assign vari "Testtt"} though there is a longer method as outline in the Smarty docs. How do you do this in a hook? For example in a hook file with ClientAreaPage, how do I change the companyname smarty variable before its used in the template in WHMCS v8+ ? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted October 31, 2020 Share Posted October 31, 2020 15 hours ago, heapmaster said: For example in a hook file with ClientAreaPage, how do I change the companyname smarty variable before its used in the template in WHMCS v8+ ? <?php add_hook('ClientAreaPage', 1, function($vars) { $newcompanyname = "heapmaster"; return array ("companyname" => $newcompanyname); }); 0 Quote Link to comment Share on other sites More sharing options...
heapmaster Posted October 31, 2020 Share Posted October 31, 2020 11 hours ago, brian! said: <?php add_hook('ClientAreaPage', 1, function($vars) { $newcompanyname = "heapmaster"; return array ("companyname" => $newcompanyname); }); Ya thats what I have and its not working in 8.0.4, I raised a support ticket 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 1, 2020 Share Posted November 1, 2020 10 hours ago, heapmaster said: Ya thats what I have and its not working in 8.0.4, I raised a support ticket what exactly are you trying to do ? the above hook would just change the company name variable used in the header - so the new variable text would be shown in Six (if there wasn't a valid logo) and also used in the page title... the above image is from v8.0.4 🙂 0 Quote Link to comment Share on other sites More sharing options...
heapmaster Posted November 1, 2020 Share Posted November 1, 2020 1 hour ago, brian! said: what exactly are you trying to do ? the above hook would just change the company name variable used in the header - so the new variable text would be shown in Six (if there wasn't a valid logo) and also used in the page title... the above image is from v8.0.4 🙂 Im trying to change the logo URL at the top from the hook and the Copyright footer of company name and date in the footer template. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 1, 2020 Share Posted November 1, 2020 6 minutes ago, heapmaster said: Im trying to change the logo URL at the top from the hook and the Copyright footer of company name and date in the footer template. well the above hook would change the companyname variable in the footer (assuming your footer uses that variable), and you would need to use JS on a hook to change the URL (or just edit the header.tpl template!). 0 Quote Link to comment Share on other sites More sharing options...
heapmaster Posted November 1, 2020 Share Posted November 1, 2020 35 minutes ago, brian! said: well the above hook would change the companyname variable in the footer (assuming your footer uses that variable), and you would need to use JS on a hook to change the URL (or just edit the header.tpl template!). Thanks, ya in my dev install this works, all three are changed in the header and footer, but my live install it does not work and they are both 8.0.4 R1, so odd..still debugging.. function client_area_companyinfo_change_it($vars) { $aryReturnArrayData = array(); $aryReturnArrayData["companyname"] = "Test Company"; $aryReturnArrayData["date_year"] = "1234"; $aryReturnArrayData["assetLogoPath"] = "/images/logo.jpg"; return $aryReturnArrayData; } add_hook("ClientAreaPage",1,"client_area_companyinfo_change_it"); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 1, 2020 Share Posted November 1, 2020 5 minutes ago, heapmaster said: Thanks, ya in my dev install this works, all three are changed in the header and footer, but my live install it does not work and they are both 8.0.4 R1, so odd..still debugging.. then assuming you haven't disabled hooking in the live site, is there any caching occurring, re cloudflare, litespeed etc... all else fails, clear the template cache and see if that helps. 0 Quote Link to comment Share on other sites More sharing options...
heapmaster Posted November 1, 2020 Share Posted November 1, 2020 2 minutes ago, brian! said: then assuming you haven't disabled hooking in the live site, is there any caching occurring, re cloudflare, litespeed etc... all else fails, clear the template cache and see if that helps. Hooking is working because I add exit; before the return and I get a blank page so the hook is being called. I cleared the template_c folder and we dont have litespeed or cloudflare and still it does not work.... 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 2, 2020 Share Posted November 2, 2020 with the same template in both live & dev installs ? 0 Quote Link to comment Share on other sites More sharing options...
heapmaster Posted November 2, 2020 Share Posted November 2, 2020 Yes, both installs are the six default html template not modified (we like to do all modifications in hooks files). 0 Quote Link to comment Share on other sites More sharing options...
heapmaster Posted November 2, 2020 Share Posted November 2, 2020 (edited) I think I figured it out, it was a hooks file in a addon that was overriding my hook. I would change it and then it would run and change it back. I fixed it by doing add_hook("ClientAreaPage",300,"..... (changing the priority of my hook to be higher) Edited November 2, 2020 by heapmaster 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted November 3, 2020 Share Posted November 3, 2020 16 hours ago, heapmaster said: I fixed it by doing add_hook("ClientAreaPage",300,"..... (changing the priority of my hook to be higher) technically, you've made the priority of your hook lower rather than higher - so your hook will effectively run later, e.g after the addon hook runs. 1 Quote Link to comment Share on other sites More sharing options...
heapmaster Posted June 15, 2021 Share Posted June 15, 2021 (edited) Thanks, now I'm having the issue after talking to the addon developer that my hook is overriding their hook. Similar to what is described here It seems variable changes made in the first hook do not get passed into the second hook and then to WHMCS. So its either one hook or the other and not both for some reason. WHMCS should pass the results of the changed variables to the second hook for processing, and then those changes of the variables from both hooks then passed to the template from WHMCS. But its not doing that. Edited June 15, 2021 by heapmaster 0 Quote Link to comment Share on other sites More sharing options...
heapmaster Posted June 21, 2021 Share Posted June 21, 2021 (edited) This needs to be fixed internally within the WHMCS code... Edited June 21, 2021 by heapmaster 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.