Jump to content

Error assign smarty variable


adixm

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...
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+ ?

Link to comment
Share on other sites

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);
});

 

Link to comment
Share on other sites

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...

ytVFu2E.png

the above image is from v8.0.4 🙂

Link to comment
Share on other sites

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...

ytVFu2E.png

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.

Link to comment
Share on other sites

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!).

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

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 by heapmaster
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 7 months later...

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 by heapmaster
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