plusplushosting Posted September 6, 2020 Share Posted September 6, 2020 Hi guys, wondering if is there any hook function that let me insert an html code/line without having to edit the template? For example if i wish to insert a line of txt below the copyright line in the footer.tpl? Thanx in advance! 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 7, 2020 Share Posted September 7, 2020 You can use this: https://developers.whmcs.com/hooks-reference/output/#clientareafooteroutput You might need to use jQuery to insert it at a specific place. 0 Quote Link to comment Share on other sites More sharing options...
plusplushosting Posted September 7, 2020 Author Share Posted September 7, 2020 Thank you! Ill take a look. 0 Quote Link to comment Share on other sites More sharing options...
plusplushosting Posted September 7, 2020 Author Share Posted September 7, 2020 I found the following but i guess i need the jquery part to add the text below the copyright line....any help will be welcome! 🙂 Thanx! <?php add_hook('ClientAreaFooterOutput', 1, function($vars){ $footer = '<p>demo</p>'; return $footer; }); 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 8, 2020 Share Posted September 8, 2020 You should just use jQuery to place it where you need. See this: jQuery("#btnCompleteOrder").before("' . preg_replace( "/\r|\n/", "", str_replace('"', '\"', $output)) . '"); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 8, 2020 Share Posted September 8, 2020 15 hours ago, plusplushosting said: I found the following but i guess i need the jquery part to add the text below the copyright line.... it would be along the lines of... <?php add_hook('ClientAreaFooterOutput', 1, function($vars){ $footer = '<script>$(document).ready(function() { $("#footer .container").append("demo"); });</script>'; return $footer; }); but depending on what you want to add there, it's probably worth mentioning that the copyright text is a language string - so you could easily use a Language Override to add specific text to it in the user's language if that's easier. 1 Quote Link to comment Share on other sites More sharing options...
plusplushosting Posted September 8, 2020 Author Share Posted September 8, 2020 Thanx guys! Hi Brian! How are you doing, hopefully you are safe and healthy! Ill give it a try and see. Yeah, with the language override can be easy but i want do it this way as i have to also replace things in the header, so i guess i have to only find the header hook function name and make the modifications there. Thanx again! 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted September 8, 2020 Share Posted September 8, 2020 You should also use the footer hook to replace things in the header, actually. You return javascript/jQuery in the footer that will update the content on the website, in any place 🙂 1 Quote Link to comment Share on other sites More sharing options...
plusplushosting Posted September 8, 2020 Author Share Posted September 8, 2020 10 minutes ago, DennisHermannsen said: You should also use the footer hook to replace things in the header, actually. You return javascript/jQuery in the footer that will update the content on the website, in any place 🙂 Great! Thanx! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 8, 2020 Share Posted September 8, 2020 3 minutes ago, plusplushosting said: How are you doing, hopefully you are safe and healthy! hola mate - absolutely fine... covid free so far! 😷 5 minutes ago, plusplushosting said: Yeah, with the language override can be easy but i want do it this way as i have to also replace things in the header, so i guess i have to only find the header hook function name and make the modifications there. in the above hook, you could change ClientAreaFooterOutput to ClientAreaHeaderOutput and it would still work... sometimes it can be better to use header rather than footer depending on what you're looking to change. 1 Quote Link to comment Share on other sites More sharing options...
plusplushosting Posted September 8, 2020 Author Share Posted September 8, 2020 Just now, brian! said: hola mate - absolutely fine... covid free so far! 😷 Thats the most important now! Glad to hear it. Thanx again! 0 Quote Link to comment Share on other sites More sharing options...
plusplushosting Posted September 8, 2020 Author Share Posted September 8, 2020 Just to know, this do work if i need insert a html or smarty code? I mean jquery will be processed after the page load or the smarty will be processed before? Just to know if the smarty will be processed if i insert it after the page load. btw, is there any function to to insert it in a specific orderform/cart.tpl? Thanx again! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 8, 2020 Share Posted September 8, 2020 5 minutes ago, plusplushosting said: Just to know, this do work if i need insert a html or smarty code? yes to HTML.. in terms of Smarty, then you're writing the hook in PHP and you can access the Smarty variables of the page in that hook - so effectively you're passing PHP variables to the JS rather than Smarty... 9 minutes ago, plusplushosting said: btw, is there any function to to insert it in a specific orderform/cart.tpl? usually what you would do is to use an if statement in the hook that determines if the current cart template theme is X and/or the current template/file is Y.... and then only if those conditions are met, do you return your changes. 1 Quote Link to comment Share on other sites More sharing options...
plusplushosting Posted September 8, 2020 Author Share Posted September 8, 2020 1 hour ago, brian! said: yes to HTML.. in terms of Smarty, then you're writing the hook in PHP and you can access the Smarty variables of the page in that hook - so effectively you're passing PHP variables to the JS rather than Smarty... Well...no i mean, if i wish insert something like..... <?php add_hook('ClientAreaFooterOutput', 1, function($vars){ $footer = '<script>$(document).ready(function() { $("#footer .container").append("{debug}"); });</script>'; return $footer; }); 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 8, 2020 Share Posted September 8, 2020 17 minutes ago, plusplushosting said: Well...no i mean, if i wish insert something like..... debug would be a bad example because the page would have loaded before the JS is run, so it wouldn't trigger a debug window to be opened. 1 Quote Link to comment Share on other sites More sharing options...
plusplushosting Posted September 8, 2020 Author Share Posted September 8, 2020 jajaja...you are making me harder man....was just an example...but the idea is there, how i could insert a smarty tag (any tag) and have it working, as you said the jquery will insert the code once the page is loaded. btw2 🙂 how can i replace a html in the page instead to append? Thanx! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted September 9, 2020 Share Posted September 9, 2020 17 hours ago, plusplushosting said: jajaja...you are making me harder man....was just an example...but the idea is there, how i could insert a smarty tag (any tag) and have it working, as you said the jquery will insert the code once the page is loaded. by the time the hook is adding the code, the smarty will have already been processed - so adding smarty that you expect to do anything is not worth it... the way to think of it is to create the content of the replacement and pass that via the jQuery - don't think of it as the template contains {$tag1} and so I can just replace it with {$tag2}... what you do is replace the content of {$tag1} with a predefined replacement value - could be text, html etc.. and more importantly, assumes that you can locate the specific position of the content you want to replace in the hook - with WHMCS, that might not always, and sadly too often, be the case. 20 hours ago, plusplushosting said: how can i replace a html in the page instead to append? replacing content with jQuery is not a magic bullet solution - at a push, i'd use it in a small limited way, but I wouldn't use it to make wholesale changes to a client area template, certainly not a cart template, unless it was a last resort. if you take your footer hook and replace the copyright content... <?php add_hook('ClientAreaHeaderOutput', 1, function($vars){ $footer = '<script>$(document).ready(function() { $("#footer .container").replaceWith("<div class=\"container\"><h2 style=\"color:red;\">New Copyright Footer</h2></div>"); });</script>'; return $footer; }); 2 Quote Link to comment Share on other sites More sharing options...
plusplushosting Posted September 9, 2020 Author Share Posted September 9, 2020 Thanx very much for the info Brian! Stay safe! 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.