ChrisTERiS Posted December 6, 2020 Share Posted December 6, 2020 (edited) Hello, Is there any way to include a template file to a hook? For example, using this code: <?php use WHMCS\View\Menu\Item as MenuItem; // Add a Panel to the end of all secondary sidebars. add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) { $thankYouMessage = '<div class="widget-content-padded">Hello World!</div>'; $secondarySidebar->addChild('test-panel', array( 'label' => 'Test Panel', 'icon' => 'far fa-handshake', 'bodyHtml' => $thankYouMessage, 'footerHtml' => 'Here is the Panel Footer!', )); // Retrieve the panel we just created. $TestPanel = $secondarySidebar->getChild('test-panel'); // Move the panel to the end of the sorting order so it's always displayed // as the last panel in the sidebar. $TestPanel->moveToBack(); }); I can have this panel in the sidebar: But as the content of this panel should be a (simple) form, I prefer to have it in a tpl file. Is there any secure way to set the value of $thankYouMessage with the output of a template file? Using ob_start() to get the content is it a secure way? Thank you Chris Edited December 6, 2020 by ChrisTERiS 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 6, 2020 Share Posted December 6, 2020 5 hours ago, ChrisTERiS said: Is there any way to include a template file to a hook? if you had to, file_get_contents would be another option - but you will likely have to check the template file exists and that it's not empty before you use it to create the content. $bodyform = file_get_contents('https://domain.com/domainsearch.tpl'); domainsearch.tpl contains the integration code for a domain search... <form action="cart.php?a=add&domain=register" method="post"> Find your Domain: <input type="text" name="query" size="20" /> <input type="submit" value="Go" /> </form> personally, i'd just add the html to the variable in the hook... even if the same form snippet is going to be used in multiple hooks. 1 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted December 6, 2020 Author Share Posted December 6, 2020 37 minutes ago, brian! said: if you had to, file_get_contents would be another option - but you will likely have to check the template file exists and that it's not empty before you use it to create the content. $bodyform = file_get_contents('https://domain.com/domainsearch.tpl'); domainsearch.tpl contains the integration code for a domain search... <form action="cart.php?a=add&domain=register" method="post"> Find your Domain: <input type="text" name="query" size="20" /> <input type="submit" value="Go" /> </form> personally, i'd just add the html to the variable in the hook... even if the same form snippet is going to be used in multiple hooks. The form should have a simple validation for empty field and check email format and don't know if it's wise to add js code there. In any case thank you very much !! 0 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted December 6, 2020 Author Share Posted December 6, 2020 @brian! Is there anything similar to $smarty->fetch() syntax for WHMCS? I want to store the template output in a variable. eg $mail_template = $smarty->fetch('mail_nl_unsubscribe.tpl'); This work in my PHP script but this not in WHMCS $ca->setTemplate('widget_newsletter'); // Render Template $test = $ca->fetch() I'm wasting my time with PHP and TPL file just because didn't found any way to use HTML in hook file. I mean it does not recognizes the css classes. eg the code below shows the icon over the input while in a normal tpl works. <div class="form-group prepend-icon"> <label for="inputFirstName" class="field-icon"> <i class="fas fa-user"></i> </label> <input type="text" name="firstname" id="inputFirstName" class="field form-control" placeholder="First Name" required> </div> 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted December 6, 2020 Share Posted December 6, 2020 23 minutes ago, ChrisTERiS said: I'm wasting my time with PHP and TPL file just because didn't found any way to use HTML in hook file. I mean it does not recognizes the css classes. I think the problem is that you're trying to call these classes on pages WHMCS doesn't expect you to.... for example, if you call it in the cart, it works fine.... but call it on the homepage, and only the top field works... i'm quickly getting around this by wrapping the first field in the registration ID class and then tweaking it further with inline styling to remove the padding - so my .tpl file contains... <div id="registration" style="padding: 0px !important"> <div class="form-group prepend-icon" > <label for="inputFirstName" class="field-icon"> <i class="fas fa-user"></i> </label> <input type="text" name="firstname" id="inputFirstName" class="field form-control" placeholder="First Name" required> </div> </div> <div class="form-group prepend-icon"> <label for="inputFirstName" class="field-icon"> <i class="fas fa-user"></i> </label> <input type="text" name="firstname" id="inputFirstName" class="field form-control" placeholder="First Name" required> </div> a better fix would be to duplicate the relevant #registration CSS values from all.css (or whatever your default template CSS file is) into custom.css (there are upto 23 entries in all.css) and then declare them as #sidebarfields and adjust template code accordingly. <div id="sidebarfields"> I hope that helps. 🙂 1 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted December 6, 2020 Author Share Posted December 6, 2020 Just now, brian! said: I hope that helps. 🙂 Only helps? You saved my mind. Thank you so much for your time. It's true that in one page I have seen it appearing well, but as I was doing continuous changes maybe I destroyed everything. Once again thank you. 0 Quote Link to comment Share on other sites More sharing options...
ChrisTERiS Posted December 6, 2020 Author Share Posted December 6, 2020 2 hours ago, brian! said: a better fix would be to duplicate the relevant #registration CSS values from all.css (or whatever your default template CSS file is) into custom.css (there are upto 23 entries in all.css) and then declare them as #sidebarfields and adjust template code accordingly. This is what I did and works fine. If you don't mind and just as a way to improve my knowledge. Is there any way to store in a variable a tpl file instead to output it? For sure this does NOT works: // Start Template $ca = new ClientArea(); $ca->initPage(); // Define the template filename to be used without the .tpl extension $ca->setTemplate('widget_newsletter'); // Render Template $ca->output(); As the template engine is the same I thought that by replacing: $ca->output(); with: $var_template = $ca->fetch(); should works. But have been mistaken. This is the code that works fine outside of WHMCS // Prepare Template $smarty = new Smarty(); require_once('./includes/smartyconfig.php'); // Prepare Smarty Variables $smarty->assign("name", $rlt_subscriber["name"]); $smarty->assign("autolink", $autolink); $mail_template = $smarty->fetch('mail_nl_unsubscribe.tpl'); 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.