dtravlos Posted May 10, 2019 Share Posted May 10, 2019 Hello, I am trying to create an addon module only for the admins. Can you help me on how I can render templates from each controller action instead of simly echo the content? On the sample addon it says @see AddonModule\Admin\Controller::index() but I can't find the docs... Also for ajax calls I can simple create actions and just echo the result as json? Thanks 0 Quote Link to comment Share on other sites More sharing options...
steven99 Posted May 10, 2019 Share Posted May 10, 2019 In the sample addon module open file: modules/addons/addonmodule/lib/Admin/Controller.php . Then find the "index" function. That's all they mean by "see" as there isn't much more In the addon modules's _output function that is used for the admin, it only expects HTML / string as a return and thus why they build it up using a string variable in the index function. You could use the smarty engine, feed it a template file local to the addon's directory, assign the variables needed, and then use the fetch function instead of display to then get the HTML, which you then return and WHMCS spits it out. I may have another post that details this a bit more. 0 Quote Link to comment Share on other sites More sharing options...
dtravlos Posted May 13, 2019 Author Share Posted May 13, 2019 Thanks it worked! I am trying to create an ajax call but the response sends the entire admin page 😕 Is there any way to have actions tha return only the json response i need and not the entire admin page? Thanks! 0 Quote Link to comment Share on other sites More sharing options...
string Posted May 13, 2019 Share Posted May 13, 2019 4 hours ago, dtravlos said: Is there any way to have actions tha return only the json response i need and not the entire admin page? I would either create a new file for ajax calls or do a "exit;" after you echo the json output. That should work. 0 Quote Link to comment Share on other sites More sharing options...
Kian Posted May 13, 2019 Share Posted May 13, 2019 <? /* Cut... */ function YourModule_output($vars) { if ($_POST['ajax']) { $result = doSomething(); header('Content-Type: application/json'); echo json_encode($result); die(); } } 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.