n3m0 Posted August 13, 2019 Share Posted August 13, 2019 I am complete noob in smarty and have reading tuts, docs provided and googling for whole day (and night), but still have no clue.. so please be patience to me.. I want to show new variable declared in hook php, and show it in certain area at clientareaproductdetails. I created test.php in hooks folder. The code is: Quote <?php function example() { global $smarty; $variable = "Hello world!"; $smarty->assign('VARIABLE_COMES_FROM_HOOK',$variable); return $VARIABLE_COMES_FROM_HOOK; } add_hook('clientareaproductdetails', 1, 'example'); ?> And I put the following inside clientareaproductdetails.tpl Quote ...... many codes above... {$VARIABLE_COMES_FROM_HOOK} .... many codes below.... But the "hello world" not show up. Please help what should I do? Note: I actually already made many functions in php and want to put inside tpl file, then I just realize whmcs using smarty. And ofc my php functions all failed to load inside tpl file. This is my next plan after I figure it out how "hook" and assign new variable works. Thank you so much and sorry for my English. n3m0 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted August 14, 2019 Share Posted August 14, 2019 <? add_hook('ClientAreaProductDetails', 1, function($vars) { $output['something'] = 'Yeah'; $output['somethingelse'] = 'Nope!'; return $output; }); Here is how you use them in tpl file: <strong>{$something}</strong> <small>{$somethingelse}</small> 0 Quote Link to comment Share on other sites More sharing options...
n3m0 Posted August 14, 2019 Author Share Posted August 14, 2019 ah! so simple!.... thank you so much! Please correct me if I am wrong. if I want to create several PHP functions, I need to create those functions outside of this code bellow : add_hook('ClientAreaProductDetails', 1, function($vars) { $output['something'] = 'Yeah'; $output['somethingelse'] = 'Nope!'; return $output; }); and call them inside it, is that correct? Or I need to create those php functionts inside it? TIA, n3m0 0 Quote Link to comment Share on other sites More sharing options...
n3m0 Posted August 14, 2019 Author Share Posted August 14, 2019 Apologize, I tried exact code from you... create only your code in my hook files, and put the following inside my tpl. <strong>{$something}</strong> <small>{$somethingelse}</small> still don't show anything in my tpl... Thank you so much for helping me, n3m0 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted August 14, 2019 Share Posted August 14, 2019 7 hours ago, n3m0 said: Apologize, I tried exact code from you... create only your code in my hook files, and put the following inside my tpl. Kian's code would work, except you're using the wrong hook point, it should be ClientAreaPageProductDetails if you're going to return variables to the template... <? add_hook('ClientAreaPageProductDetails', 1, function($vars) { $something = 'Yeah'; $somethingelse = 'Nope!'; return array ("something" => $something, "somethingelse" => $somethingelse); }); 0 Quote Link to comment Share on other sites More sharing options...
n3m0 Posted August 14, 2019 Author Share Posted August 14, 2019 I am very sure on the correct place. Because if I tested it by inserting wrong code, it caught the error. But I will try again. Thank you all for the enlightenment, do really appreciate for your help and time spent on this. Regards, N3m0 0 Quote Link to comment Share on other sites More sharing options...
HostT Posted March 31, 2021 Share Posted March 31, 2021 This def does not work, it adds the data to `addons_html` for some reason (at least when I use `ClientAreaHomepage`). For anybody trying to do something like this, you can always check this by adding `{debug}` to your smarty template and it will popup all the variables. The easiest solution for this is to just add the variables to the global smarty variable. This will work anywhere in code or hooks, as smarty variables (as of 8.1 are still stored in the global `$smartyvalues` parameter) add_hook( 'ClientAreaHomepage', 2, function( $params ) { global $smartyvalues; $smartyvalues['testME'] = 'YUP YUP'; }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted March 31, 2021 Share Posted March 31, 2021 6 minutes ago, HostT said: This def does not work, it adds the data to `addons_html` for some reason (at least when I use `ClientAreaHomepage`). ClientAreaHomepage returns HTML rather than an array... ClientAreaPageHome would return an array/variables to the template. 0 Quote Link to comment Share on other sites More sharing options...
ZARTURA Posted April 25 Share Posted April 25 Use 'ClientAreaPage' to execute across the entire client area pages, Products, Templates, Carts, etc. Saves me time! <? add_hook('ClientAreaPage', 1, function($vars) { $output['something'] = 'Yeah'; $output['somethingelse'] = 'Nope!'; return $output; }); 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.