Jump to content

hook to insert html code in the template


plusplushosting

Recommended Posts

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.

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
});
Link to comment
Share on other sites

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